Tom Tucker
Tom Tucker

Reputation: 11896

Binding Multiple Command Objects of Same Type in Spring MVC

I have a several command objects of the same type to bind, each of which represents a row from a form. How do I bind these in an annotation based controller? How do I access them on the JSP?

Upvotes: 1

Views: 1756

Answers (1)

axtavt
axtavt

Reputation: 242686

Create a form object containing these rows

public class FooList {
    private List<Foo> foos;    
    ...
}

and use it as a command object. To bind rows to form fields, use indexed paths:

<form:form modelAttribute = "fooList" ...>
    <ul>
    <c:forEach items = "${fooList.foos}" varStatus = "s">
        <li><form:input path = "foos[${s.index}].name" /></li>
    </c:forEach>
    </ul>
</form:form>

Upvotes: 4

Related Questions