Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple forms in Spring

 
Karthikjava karthik
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a jsp page in that i have multiple form tags like

<form:form action="action1.htm" method="post" commandName="commandName1" > </form>

<form:form action="action2.htm" method="post" commandName="commandName2" > </form>

<form:form action="action3.htm" method="post" commandName="commandName3" > </form>

<form:form action="action4.htm" method="post" commandName="commandName4" > </form>

in this , i want to call different controller for each action & return the ModelAndView Object to the parthicular form tag

Can anyone help me out on this?

thanks in advance

Karhtik
 
Ayan mallick
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think going for an annotation way would be a better solution here. because in that case we can handle all forms initialization inside a single controller all form handling also inside a single controller.
I don't know whether we can have array of command class or array of command names inside single controller much like supported http methods like get and post.

with annotaion when you create the form backing object you have to create all form backing object and set then in model map for preinitialization.
but would you please tell me why you need all forms in a single page.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing to prevent you from having multiple forms on a page, just don't nest them. Typically with newer versions of spring you use the modelAttribute tag not the commandname tag. You obviously can't submit multiple forms at once, typically you would use AJAX for this. You have not really given us enough information to help you determine if the approach you are taking is the best one.
 
Ayan mallick
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think commandname and modelattribute are for diff pupose all-together. command name for initialization purpose by the name pre-intialized form is set in request when displaying form for first time.
model attribute is posted data which is set in request scope. correct me if i am wrong because that's what i know.
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are absolutely identical. As a matter of fact I think in code one calls the other. CommandName just lingers on for historical reasons.

Discussion of it here: http://chompingatbits.com/2009/08/25/spring-formtag-commandname-vs-modelattribute/
 
Ayan mallick
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm i didn't know that.That's why i love this forum so much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic