title: Checkbox values do not bind into object when false?
body: <p>I used <strong>ModelAttribute</strong> to bind object in Spring web application.</p>
  
  <p>Once I notice that, <strong>in case an object has an boolean value A is true, its value will not be updated if we uncheck A's checkbox</strong>.</p>
  
  <p>For example, I have a Lesson object which has the attribute "active" = true.
  In "Edit Lesson" view, I make a checkbox which bind into "active". Things work well if the checkbox is checked (the binding object reflect the changes), but the object lesson will not change if we un-check the checkbox.</p>
  
  <p><em>Further study tells me that's because the checkbox value may not get submitted by browser (this is an in-design of HTML). So I have to use the ugly <code>request.getParameter</code> to check if the value is set.</em></p>
  
  <p>I just come by <a href="https://stackoverflow.com/questions/8119569/mv3-duplicate-query-string-values-for-checkbox-true-false-for-boolean">this question</a>, and I see that asp.net mvc provide a way to work around it more elegantly. I think Spring must provide something similarly. Does anyone know how to do that?</p>
  
  <p>Following is my code:</p>
  
  <p>Controller code:</p>
  
  <pre><code>    @RequestMapping(value="/test", method = RequestMethod.POST)
      public String processEditLesson(@Valid Lesson lesson, BindingResult bindingResult, Model model) {
          System.out.println("Lesson is active: " + lesson.isActive()); // still "true" even if the checkbox is unset
  
          // Current work-around
          String isActive = request.getParameter("active");
          if (StringUtils.isNotNullOrEmpty(isActive)) {
              lesson.setActive(true);
          } else {
              lesson.setActive(false);
          }
          ...
      }
  </code></pre>
  
  <p>View code:</p>
  
  <pre><code>&lt;form id="lesson" class="EditorForm" action="${rc.getContextUrl('/test.html')}" method="post" &gt;
  
      &lt;fieldset&gt;
          &lt;legend&gt;&lt;@spring.message code="lesson.edit"/&gt;&lt;/legend&gt;
          &lt;@spring.formHiddenInput "lesson.id" /&gt;
          &lt;@spring.formHiddenInput "lesson.studio.id" /&gt;
  
          &lt;div class="Entry"&gt;
              &lt;label for="name"&gt;&lt;@spring.message code="lesson.message"/&gt;&lt;/label&gt;
              &lt;@spring.formInput "lesson.message" /&gt;
              &lt;span class="ErrorMessage"&gt;&lt;@spring.showErrors "&lt;br/&gt;" /&gt;&lt;/span&gt;
          &lt;/div&gt;
  
          &lt;input type="checkbox" name="active" checked="checked" /&gt;
          &lt;label for="active"&gt;${rc.getMessage('lesson.active')}&lt;/label&gt;
  
          &lt;input type="submit" value="&lt;@spring.message code='common.update' /&gt;" /&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>