Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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 Murach's Java Servlets and JSP this week in the Servlets 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
Similar Threads
The requested resource is not available.
How to avoid using session scope in this case?
what is "dynamic" form bean ?
Two forms in a page problem