title: Getting null values from checkboxes
body: <p>I am working on a simple Spring MVC project. I am having trouble getting values from checkboxes. What I mean is when a user checks 2 boxes out of 3, all 3 are binded to a list with non-checked values as null. That's wrong. I just want values that are checked. Those that didn't get checked should not come to list at all. 
  This is a snippet of my code:
  POJO:</p>
  
  <pre><code>public class Student{
  private List&lt;StudentCourses&gt; sc;
  //getters and setters
  }
  
  public class StudentCourses{
  private int courseID;
  private String courseName;
  private Character grade;
  private String semesterID;
  //getters and setters
  } 
  </code></pre>
  
  <p>This is what I send from my controller: </p>
  
  <pre><code>@RequestMapping(value = "/selectclasses", method = RequestMethod.POST)
  public String selectClasses(Model m) {
  Student s = new Student();
  List&lt;StudentCourses&gt; coursesList = new ArrayList&lt;StudentCourses&gt;();
  coursesList.add(new StudentCourses("Eng 101", '-', "SP 16"));
  coursesList.add(new StudentCourses("Math 140", '-', "SP 16"));
  coursesList.add(new StudentCourses("CS 442", '-', "SP 16"));
  m.addAttribute("coursesList", coursesList);
  m.addAttribute("student", s);
  return "selectclasses";
  }
  </code></pre>
  
  <p>This is what I have in my selectclasses.jsp:</p>
  
  <pre><code>    &lt;form:form modelAttribute="student" method="post" action="/success"&gt;
          &lt;table&gt;
              &lt;c:forEach items="${coursesList}" var="r" begin="0" varStatus="status"&gt;
                  &lt;form:checkbox path="sc[${status.index }].courseName" value="${r.courseName}" label="${r.courseName}" /&gt;
              &lt;/c:forEach&gt;
          &lt;/table&gt;
          &lt;input type="submit" id="submit" name="submit" value="Submit" /&gt;
      &lt;/form:form&gt;
  </code></pre>
  
  <p>I don't know why null is passed to the "sc.courseName" when it's not checked. What am I doing wrong? Or is there a work around it?</p>
  
  <p>Please help 
  Thanks. </p>