views:

27

answers:

1

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?

+2  A: 

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>
axtavt