With Spring 2 form tags, how can bind list in a list
I have an object with a list of object A with a list of object B.
Model:
public class ObjectA implements Serializable {
private List<ObjectB> objectBs;
}
public class ObjectB implements Serializable {
private String name;
}
with getters and setters
DTO: use in my front end controller with Spring MVC 2
public class FrontObject implements Serializable {
private List<ObjectA> objectAs;
}
with getters and setters
In my JSP (I use forEach tag to add somes stuff, I know the form:checkboxes tag):
<c:forEach items="${objectAsList}" var="item">
<!-- it works -->
<form:checkbox path="objectAs" value="${item}"/>
<c:forEach items="${item.objectBs}" var="itemB">
<!-- whats the path? -->
<form:checkbox path="????" value="${itemB}" />
</c:forEach>
</c:forEach>
What's the syntax for the开发者_开发技巧 path (of the form tag checkbox) to bind a list of objectB in a list of objectA
Maybe something like
<form:checkbox path="objectAs.objectBs" value="${itemB}" />
Return org.springframework.beans.NotReadablePropertyException: Invalid property
Normally, the path is the name of the value contained by your object. In your case, it's "name"
I think it could be
<form:checkbox path="objectAs.objectBs.name" value="${itemB.name}" />
or maybe :
<c:forEach items="${item.objectBs}" var="itemB" varStatus="i">
<form:checkbox path="objectAs.objectBs[i.index].name" value="${itemB.name}" />
</c:forEach>
精彩评论