Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with multiple form beans

 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Thanks
Shiva
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Thanks
Shiva
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic