开发者

Binding Multiple Command Objects of Same Type in Spring MVC

开发者 https://www.devze.com 2023-01-23 00:42 出处:网络
I have a several command objects of the same type to bind, each of which represents a row from a form. How do I 开发者_StackOverflow社区bind these in an annotation based controller? How do I access th

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


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

精彩评论

暂无评论...
验证码 换一张
取 消