File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Multiple forms in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Multiple forms in Spring " Watch "Multiple forms in Spring " New topic
Author

Multiple forms in Spring

Karthikjava karthik
Greenhorn

Joined: Apr 03, 2013
Posts: 2
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

Joined: Nov 17, 2012
Posts: 46
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

Joined: Mar 07, 2010
Posts: 1672
    
    7

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.


[How To Ask Questions][Read before you PM me]
Ayan mallick
Ranch Hand

Joined: Nov 17, 2012
Posts: 46
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

Joined: Mar 07, 2010
Posts: 1672
    
    7

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

Joined: Nov 17, 2012
Posts: 46
hmm i didn't know that.That's why i love this forum so much
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple forms in Spring