Reputation: 9201
I am working with Spring MVC 2.5.
Oftentimes, I am only using one form in all my JSP. Now I need to add another form into the same JSP.
My question is, will Spring MVC still support the same lifecycle method whichever form I submit?
I mean, the same databinding, validation, errorhandling, form controller etc?
<div>
<form:form method="post" commandName="station">
</form>
</div>
<div>
<form:form method="post" commandName="fields">
</form>
</div>
Upvotes: 4
Views: 6472
Reputation: 403591
The old-style controllers you're using can only support one command object, and therefore only one form, at a time. @Arthur's answer shows that you can't really put both forms on one page, because any given controller will only supply one form object, you'll never get both active at once.
If you want to do this, you're going to have to stop using the old-style controllers (which are obsolescent in Spring 2.5, and deprecated in Spring 3), and use annotated controllers, which are much more flexible. You can mix up your forms pretty much as complex you want.
Upvotes: 3
Reputation: 33783
Spring SimpleFormController just support one kind of Command object. So if you want to use two distinct Spring form into The same JSP, you have to create two SimpleFormController. And inside your JSP, do as follows to avoid some exception
<c:if test="${not empty station}">
<div>
<form:form method="post" commandName="station">
</form>
</div>
</c:if>
<c:if test="${not empty fields}">
<div>
<form:form method="post" commandName="fields">
</form>
</div>
</c:if>
Upvotes: 3