• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

two actionForms for one action class?

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
What are your superhero powers? Go ahead and try them on this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic