aspose file tools*
The moose likes Struts and the fly likes two actionForms for one action class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "two actionForms for one action class?" Watch "two actionForms for one action class?" New topic
Author

two actionForms for one action class?

rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Hi,
Is there any way to use two action forms for one action class.
I have the following situation: one html form (form1) and a "go" button for sample1.jsp, another html form (form2) and "submit" button for sample2.jsp.
Once user clicks on "go" button, she will be directed to sample2.jsp, form1 values will be used and displayed on sample2.jsp. Once user clicks on "submit" button on sample2.jsp, form2 values should be saved to database.
I need to desgin one action form (actionForm1) for form1 to be retrived and displayed on sample2.jsp, and design another action form (actionForm2) to be retrieved and saved to database. Thus, the action class I design for sample2.jsp needs two actionForms. I am wondering there is any way to set up
two forms for one action class (in struts-config and elsewhere)?
regards,
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Do you really need 2 action forms for this? are you ok with having 1 action form that is shared by both the jsps. You can define all properties linked to page1.jsp and page2.jsp in the same action form. In the submit of page1 forward to page2 using action mapping.
config.xml entry might look like this:

so multiPageForm will be available to page2.jsp. You can render all the values that were entered in page1. page2 related properties will obviusly be blank. Then on the submit of page2 , you can extract the consolidated values from multiPageForm and persist to database in your action class.
C'd probably look like this..
rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Thanks for enlightening me, this is something I did not know.
Really appreciate it. I will try it out.
regards,

Originally posted by karthik Guru:
Do you really need 2 action forms for this? are you ok with having 1 action form that is shared by both the jsps. You can define all properties linked to page1.jsp and page2.jsp in the same action form. In the submit of page1 forward to page2 using action mapping.
config.xml entry might look like this:

so multiPageForm will be available to page2.jsp. You can render all the values that were entered in page1. page2 related properties will obviusly be blank. Then on the submit of page2 , you can extract the consolidated values from multiPageForm and persist to database in your action class.
C'd probably look like this..
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
Originally posted by rick collette:
I will try it out.


But then let me tell you upfront that form validation might get a little complicated in this case. Am referring to the validate() method in your form. Since all values are not available when you go to the page2, you s'd only validate for the values that were entered in page1. Then on page2 submit, you might validate all the action form properties.
rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Thanks karthik:
Very helpful. I will try out both using once form or two forms.
regards,

Originally posted by karthik Guru:

But then let me tell you upfront that form validation might get a little complicated in this case. Am referring to the validate() method in your form. Since all values are not available when you go to the page2, you s'd only validate for the values that were entered in page1. Then on page2 submit, you might validate all the action form properties.
 
jQuery in Action, 2nd edition
 
subject: two actionForms for one action class?