如果我有一个列表对象,我知道我可以使用下面的代码将类属性字段绑定到表单。
<c:forEach items="${items}" var="i" varStatus="itemsRow">
<input name="items[${itemsRow.index}].fieldName" type="text"/>
</c:forEach> <form:errors path="items" />
如果属性是Set对象,该怎么办?我在Controller类中读过initBinder,但它不起作用。任何人都可以粘贴代码来完成这个吗?
答案 0 :(得分:0)
您需要使用复选框控件:
<form:form>
<table>
<tr>
<td>Interests:</td>
<td>
<%-- Approach 2: Property is of an array or of type java.util.Collection --%>
Quidditch: <form:checkbox path="preferences.interests" value="Quidditch"/>
Herbology: <form:checkbox path="preferences.interests" value="Herbology"/>
Defence Against the Dark Arts: <form:checkbox path="preferences.interests"
value="Defence Against the Dark Arts"/>
</td>
</tr>
</table>
</form:form>
了解详情