File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Issue with multiple form beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Issue with multiple form beans" Watch "Issue with multiple form beans" New topic

Issue with multiple form beans

shiva viswanathan
Ranch Hand

Joined: Aug 12, 2004
Posts: 152
Hi All ,

I have a JSP page in which there are 2 html forms each associated with a particular form bean .
Once I submit the page i need to get both the form beans in my action class.
can anyone give some pointers

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In Struts, the action parameter of an <html:form> tag is an action defined in the struts-config.xml file. Each action is associated with a particular form.

Even though there are two forms on a page, they are each submitted separately unless you create javaScript that will submit them together. There is a one-to-one relationship between an action and a form bean. So, the short answer to your question is no, you can't read two form beans at the same time on a submit.

However, there's no reason you can't have two struts actions that both use the same action class. In this case, the action class can decide which form bean to cast it's ActionForm input parameter to.

For example, let's suppose your action class is a subclass of DispatchAction, which means that it will forward to different methods named for the contents of a specified input field, such as "edit" or "delete". In this case, both the edit() and delete() methods can cast to different suclasses of ActionForm.

Consultant, Sima Solutions
shiva viswanathan
Ranch Hand

Joined: Aug 12, 2004
Posts: 152
Thanks Merill ,

Is there any way to submit 2 forms at once in javascript .
If so , how can i obtain both in my action form .

One of the assumptions I am making is that when a form is submitted the corresponding form bean gets set into session. I have already tried this and it works.

So are you saying that the solution to my problem is more associated with javascript rather than struts .

Also in such a case do i create the 2 forms using html:form or ordinary form tag in html

I agree. Here's the link:
subject: Issue with multiple form beans
It's not a secret anymore!