File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes How Do I Handle Two Action Forms? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How Do I Handle Two Action Forms?" Watch "How Do I Handle Two Action Forms?" New topic
Author

How Do I Handle Two Action Forms?

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I am stuck and need your knowledge and experience.
When the button is my JSP is clicked, there are two action forms involved, threadForm and postForm.
The threadForm is populated by hidden fields and text fields that are passed from the JSP. All the properties of the threadForm are to be inserted into a table in the database by the threadInsert() method and this method returns a primitive int threadID.
The properties in the postForm are also populated by hidden fields and text fields that are passed from the same JSP, except that the postForm has one additional properties - threadID, which is obtained from the insertion of the threadForm into the database. Thereafter, all the properties of the postForm are to be inserted into another table in the database by the postInsert() method.
How do I handle this situation? Please help.
Rick Hightower
Author
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
Please post a code snippet of the JSP with the two forms.


Rick Hightower is CTO of Mammatus which focuses on Cloud Computing, EC2, etc. Rick is invovled in Java CDI and Java EE as well. linkedin,twitter,blog
David Yutzy
tumbleweed and gunslinger
Ranch Hand

Joined: Jun 29, 2001
Posts: 192
I understand what you are trying to accomplish, but not sure on what the problem is?
I don't necessarily need code, but are you using DispathAction? If not, just a standard action servlet? Are you using DynaForms or form classes?
Typically in the scenario you descibe, you have a single form and the ID is null or blank in your first process, then, when passed back to the same JSP, the ID now has a value and is posted during the second process you describe.
Your action method would need to check the value of ID to see if you need to perform the first or second action, based on whether the ID is null or not.
I personally would recommend using DispatchAction instead and based on which option is clicked, call the appropriate method, rather than have a single method doing both processes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Do I Handle Two Action Forms?