title: Spring 3.1 Form and List Binding
body: <p>I have not been able to find a solution on this yet after searching and searching.</p>
  
  <p>Using Spring 3.1</p>
  
  <p>I have a form where I would like the user to be able to add multiple point of contacts (poc). In my JSP I have a submit button for adding a poc. It goes to a Spring Controller, gets the current list of pocs from the domain object (which will be empty at first), adds the poc to the list and then puts the domain object back into the model before returning to the same view. Then the user will ultimately submit the entire page which will go to the controller and save the entire object to persistence.</p>
  
  <p>I have tried various attempts and come up with different results from only being able to add one poc with a new one overwriting the existing, to not being able to get the entered poc displayed on the form. I will put the code I currently have.</p>
  
  <p>JSP:</p>
  
  <pre><code>&lt;form:form method="post" commandName="request"&gt;
  
     ...
  
     &lt;h2&gt;POC:&lt;/h2&gt;
     &lt;input type="text" name="newPoc"/&gt;
     &lt;input type="submit" name="addPoc" value="Add POC"/&gt;
  
     &lt;table&gt;
          ...
          &lt;c:forEach items="${request.pointOfContacts}" var="poc" varStatus="vs"&gt;
               &lt;tr&gt;
                   &lt;td&gt;&lt;form:label path="pointOfContacts[${vs.index}].name/&gt;&lt;/td&gt;
                    .....
          &lt;/c:forEach&gt;
  
          ......
  
      &lt;/table&gt;
  
  &lt;/form:form&gt;
  </code></pre>
  
  <p>Spring Controller:</p>
  
  <pre><code>@RequestMapping(value="/request", method=RequestMethod.POST, param="addPoc")
  public Sring addPoc(@RequestParam String newPoc, MyRequest req, Model model) {
     PointOfContact poc = new PointOfContact();
     poc.setName(newPoc);
     List&lt;PointOfContact&gt; pocs = req.getPointOfContacts();
     pocs.add(poc);
     req.setPointOfContacts(pocs);
     model.addAttribute("request", req);
     return "requestForm";
  }
  </code></pre>
  
  <p>Domain Objects</p>
  
  <pre><code>@Entity
  public class MyRequest {
     ...
  
     @OneToMany(Cascade=CascadeType.ALL)
     private List&lt;PointOfContact&gt; pointOfContacts = new ArrayList&lt;PointOfContact&gt;();
  
     .....
  }
  
  @Entity
  public class PointOfContact {
     ...
  
     private String name;
  
    ....
  }
  </code></pre>
  
  <p>Does anybody have any solutions? I have seen various posts about AutoPopulatingList, is this a solution? If so how would I use it in this example.</p>