• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt regarding action class

 
san geetha
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iam new to struts framework, need to clarify few things before i start off with my project. When a new java class is written by extending the action class, we need to override the execute() method. In my scenario there are different segments in my execute method, that are executed in a conditional loop.
So is it advisable to have private methods in the java class file that i write instead of writing a seperate class file for these(cos my project is very small, consists of 4 screens)
What is the general way adopted while using struts framework?

Thanks,
Sangeeta
 
John Smith
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's good practice to seperate out your action classes, it's not a lot of work really. Generally you should call each action twice, once for initialisation and once to actually do the action and select an appropriate forward. the easiest way to do this is using the parameter attribute in your action mappings (struts-config.xml). This is assuming your "screens" are jsp forms, if not you may want to drop the initialisation calls, hope this makes helps
 
san geetha
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that did help me decide.

Cud u explain this:

the easiest way to do this is using the parameter attribute in your action mappings (struts-config.xml).


jus a sample of xml file wud do.

Regards,
Sangeeta
 
John Smith
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like such, these actions both use the same class, in the execute method I use an if statement on mapping.getParameter() to see wich action is being called

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic