Single Checkbox
Note that the hidden field is neccessary to bind when the checkbox is unchecked.
Multiple Checkboxes
One way of binding multiple checkboxes is to create a child array where its objects have a boolean flag to indicate selected status.
Note that the hidden field is neccessary to bind when the checkbox is unchecked.
<spring:bind path="command.myBooleanProperty">
<input type="hidden" name="_<c:out value="${status.expression}"/>">
<input type="checkbox" name="<c:out value="${status.expression}"/>" value="true"
<c:if test="${status.value}">checked</c:if>/>
</spring:bind>
</c:forEach>Multiple Checkboxes
One way of binding multiple checkboxes is to create a child array where its objects have a boolean flag to indicate selected status.
<c:forEach items="${command.childArray}" var="child" varStatus="loopStatus">
<spring:bind path="command.childArray[${loopStatus.index}].selected">
<input type="hidden" name="_<c:out value="${status.expression}"/>">
<input type="checkbox" name="<c:out value="${status.expression}"/>" value="true"
<c:if test="${status.value}">checked</c:if>/>
</spring:bind>
</c:forEach>
本文介绍如何使用Spring MVC框架中的绑定功能来处理单个和多个复选框的状态。对于单个复选框,需要一个隐藏字段来绑定未选中状态;对于多个复选框,则可以通过创建包含布尔标志的对象数组来实现绑定。
1371

被折叠的 条评论
为什么被折叠?



