---
title: "spring bind   checkbox 传递值问题"
author: "yanglei008"
date: "2008-07-21T17:09:45Z"
tags: []
slug: "spring-bind-checkbox"
draft: false
lastmod: "2008-07-21T17:09:45Z"
id: 217166
url: "https://yanglei008.iteye.com/blog/217166"
---

Single Checkbox
Note that the hidden field is neccessary to bind when the checkbox is unchecked.

```java

       <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.

   
```java
 <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>
```