title: Spring MVC, capture List of objects like @ModelAttribute
body: <p>I have Test class and i have jsp page that contains inputs binded to the list of tests objects. I want to take my list of tests back from my jsp with edited information. 
  My Test Class is:</p>
  
  <pre><code>@Entity
  @Table(name = "[NewMVC].[dbo].[Tests]")
  public class Test {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private int id; 
  
      @Column(name = "testQuestion")
      private String testQuestion;
  
      @Column(name = "optionOne")
      private String optionOne;
  
      @Column(name = "optionTwo")
      private String optionTwo;
  
      @Column(name = "optionThree")
      private String optionThree;
  
      @Column(name = "subjectType")
      private int subjectType;
  
      @Column(name = "correctOptionNumber")
      private int correctOptionNumber; 
          //gets, sets...
  </code></pre>
  
  <p>And i have a jsp in which i can edit list with tests: </p>
  
  <pre><code>   &lt;form:form action="saveTestsEdits" method="POST" modelAttribute = "testWrapper"&gt;
  
      &lt;c:forEach items="${testWrapper.testList}" var="test" varStatus="i"&gt;
      &lt;h2&gt; Test number ${i.index+1} &lt;/h2&gt;
      &lt;form:hidden value="${test.id}" path = "testList[${i.index}].id" /&gt;
      &lt;table&gt;
          &lt;tr&gt;&lt;td&gt;Test Question:&lt;/td&gt; &lt;td&gt;&lt;form:input path = "testList[${i.index}].testQuestion" value = "${test.testQuestion}"/&gt; &lt;/td&gt;&lt;/tr&gt;
          &lt;tr&gt;&lt;td&gt;Option one: &lt;/td&gt; &lt;td&gt;&lt;form:input path = "testList[${i.index}].optionOne" value= "${test.optionOne}"/&gt; &lt;/td&gt;
          &lt;td&gt;        
          &lt;c:choose&gt;
          &lt;c:when test="${test.correctOptionNumber == 1}"&gt; &lt;form:radiobutton path = "testList[${i.index}].correctOptionNumber" value = "1" checked = "checked"/&gt; &lt;/c:when&gt;
          &lt;c:otherwise&gt;&lt;form:radiobutton path = "testList[${i.index}].correctOptionNumber" value = "1"/&gt; &lt;/c:otherwise&gt; 
          &lt;/c:choose&gt; 
          &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;&lt;td&gt;Option two: &lt;/td&gt; &lt;td&gt;&lt;form:input path = "testList[${i.index}].optionTwo" value= "${test.optionTwo}"/&gt; &lt;/td&gt;
          &lt;td&gt;        
          &lt;c:choose&gt;
          &lt;c:when test="${test.correctOptionNumber == 2}"&gt; &lt;form:radiobutton path = "testList[${i.index}].correctOptionNumber" value = "2" checked = "checked"/&gt; &lt;/c:when&gt;
          &lt;c:otherwise&gt;&lt;form:radiobutton path = "testList[${i.index}].correctOptionNumber" value = "2"/&gt; &lt;/c:otherwise&gt; 
          &lt;/c:choose&gt; 
          &lt;/td&gt;
          &lt;/tr&gt;
  
  
          &lt;tr&gt;&lt;td&gt;Option three: &lt;/td&gt; &lt;td&gt;&lt;form:input path = "testList[${i.index}].optionThree" value= "${test.optionThree}"/&gt; &lt;/td&gt;
          &lt;td&gt;        
          &lt;c:choose&gt;
          &lt;c:when test="${test.correctOptionNumber == 3}"&gt; &lt;form:radiobutton path = "testList[${i.index}].correctOptionNumber" value = "3" checked = "checked"/&gt; &lt;/c:when&gt;
          &lt;c:otherwise&gt;&lt;form:radiobutton path = "testList[${i.index}].correctOptionNumber" value = "3"/&gt; &lt;/c:otherwise&gt; 
          &lt;/c:choose&gt; 
          &lt;/td&gt;
  
          &lt;/tr&gt;
          &lt;tr&gt;&lt;th&gt;Subject type:&lt;/th&gt;&lt;/tr&gt;
          &lt;tr&gt;&lt;td&gt;Georaphy: &lt;/td&gt; 
          &lt;td&gt;        
          &lt;c:choose&gt;
          &lt;c:when test="${test.subjectType == 3}"&gt; &lt;form:radiobutton path = "testList[${i.index}].subjectType" value = "3" checked = "checked"/&gt; &lt;/c:when&gt;
          &lt;c:otherwise&gt;&lt;form:radiobutton path = "testList[${i.index}].subjectType" value = "3"/&gt;&lt;/c:otherwise&gt; 
          &lt;/c:choose&gt; 
          &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;&lt;td&gt;Mathematics: &lt;/td&gt; 
          &lt;td&gt;        
          &lt;c:choose&gt;
          &lt;c:when test="${test.subjectType == 4}"&gt;&lt;form:radiobutton path = "testList[${i.index}].subjectType" value = "4" checked = "checked"/&gt; &lt;/c:when&gt;
          &lt;c:otherwise&gt;&lt;form:radiobutton path = "testList[${i.index}].subjectType" value = "4"/&gt;&lt;/c:otherwise&gt; 
          &lt;/c:choose&gt; 
          &lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;&lt;td&gt;History: &lt;/td&gt; 
          &lt;td&gt;        
          &lt;c:choose&gt;
          &lt;c:when test="${test.subjectType == 5}"&gt;&lt;form:radiobutton path = "testList[${i.index}].subjectType" value = "5" checked = "checked"/&gt; &lt;/c:when&gt;
          &lt;c:otherwise&gt;&lt;form:radiobutton path = "testList[${i.index}].subjectType" value = "5"/&gt;&lt;/c:otherwise&gt; 
          &lt;/c:choose&gt; 
          &lt;/td&gt;
          &lt;/tr&gt;
  
      &lt;/table&gt;
      &lt;br&gt;        
      &lt;/c:forEach&gt;
      &lt;input type="submit" value="Submit" /&gt;
  &lt;/form:form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Actually i'm not sending to the page List clearly but i have a special class called TestWrapper which looks like:</p>
  
  <pre><code>public class TestWrapper {
  
      private List&lt;Test&gt; testList = null;
  
      public TestWrapper(List&lt;Test&gt; testList) {
  
          this.testList = testList;
      }
  
      public void setTestList(List&lt;Test&gt; testList) {
  
          this.testList = testList;
      }
  
      public List&lt;Test&gt; getTestList() {
  
          return testList;
      }
  
  }
  </code></pre>
  
  <p>I tried to use: </p>
  
  <pre><code>@RequestMapping(value="/saveTestsEdits", method = RequestMethod.POST)
       public String register(@ModelAttribute("testWrapper")TestWrapper testWrapper , HttpServletRequest request)
  </code></pre>
  
  <p>But it gives me an exception: </p>
  
  <pre><code>SEVERE: Servlet.service() for servlet [appServlet] in context with path [/mvc] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.andrew.models.TestWrapper]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.andrew.models.TestWrapper.&lt;init&gt;()] with root cause
  java.lang.NoSuchMethodException: com.andrew.models.TestWrapper.&lt;init&gt;()
  </code></pre>
  
  <p>Thank you very much!</p>