Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple action forms in one action class

 
anvi kon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone tell me, Is it possible to set multiple action forms in one action class?

Here is the case.


thanks


 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would think that would work, as long as firstForm1 and firstForm2 are either the class you specified as the form class for the action or they are super classes of it. Also, capitalizing your class names, and camel casing your object names may make your code a little easier to read.
 
anvi kon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please explain with more detail using my example?


thanks
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well first off I made an assumption here, and maybe its an incorrect one, that you are always calling this action class using the same action. To tell you more I'd need to see your struts-config.xml entries for the actions that are going to go to this Action class, what classes you are using for the form beans for each action, and how those form beans fit into your class hierarchy with firstForm1 and firstForm2.
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always, better to use instanceof in your conditions

This can be achieved if you have same action class mapped with different action paths and you submit different forms accordingly from several JSPs

i.e. Say you have configured Action1 in struts-config with Form1 (used in JSP1), Form2 (used in JSP2), Form3 (used in JSP3). If you are submitting form JSP1 then you would get the instance of Form1 in the Action1's method. Similarly JSP 2 & 3

I prefer not to have such scenarios since for developing it may be easier but for maintenance?? Never
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic