title: Spring mvc add multiple rows
body: <p>i need your help as the title says i have a problem inserting multiple rows from a jsp form. The code is from an answer from this site.</p>
  
  <p>Controller</p>
  
  <pre><code>@ModelAttribute("programform")
  public ProgramForm populatePojos() {
      // Don't forget to initialize the pojos list or else it won't work
      ProgramForm programform = new ProgramForm();
      List&lt;Programs&gt; programs = new ArrayList&lt;Programs&gt;();
      for(int i=0; i&lt;2; i++) {
          programs.add(new Programs());
  
      }
      programform.setPrograms(programs);
      return programform;
  }
  
  
  
  
  @RequestMapping(value = "/createprog")
  public ModelAndView tiles2(@ModelAttribute("programform") ProgramForm  programform,
          BindingResult result) {
      //Map&lt;String, Object&gt; model = new HashMap&lt;String, Object&gt;();
      //model.put("articles",  articleService.listArticles());
  
      return new ModelAndView("createprogram");
  }
  
  
  @RequestMapping(value = "/saveprogram", method = RequestMethod.POST)
  public ModelAndView saveProgram(@ModelAttribute("programform") ProgramForm  programform,
          BindingResult result) {
      for(Programs programs : programform.getPrograms()) {
             System.out.println(programs.getProgram_id());
             articleService.addProgram(programs);
          }
  </code></pre>
  
  <p>jsp</p>
  
  <pre><code> &lt;c:url var="saveProgramUrl" value="/articles/saveprogram.html" /&gt;
  &lt;form:form modelAttribute="programform" method="POST" action="${saveProgramUrl}"&gt;
  &lt;table&gt;
  &lt;tr&gt;
              &lt;th&gt;ProgramId&lt;/th&gt;
              &lt;th&gt;Date&lt;/th&gt;
              &lt;th&gt;Type&lt;/th&gt;
              &lt;th&gt;Start&lt;/th&gt;
              &lt;th&gt;End&lt;/th&gt;
              &lt;th&gt;Location&lt;/th&gt;
              &lt;th&gt;User&lt;/th&gt;
              &lt;th&gt;Program Name&lt;/th&gt;
  &lt;/tr&gt;
      &lt;tr&gt; 
                  &lt;th&gt;&lt;form:input path="programs[0].program_id" /&gt;&lt;/th&gt;
                   &lt;th&gt; &lt;form:input path="programs[0].date" id="datepick" class="date-pick"/&gt;
          &lt;script type="text/javascript"&gt;
              datepickr('datepick', { dateFormat: 'Y-m-d' });
          &lt;/script&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[0].type" /&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[0].start" /&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[0].end" /&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[0].location" /&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[0].user_id" /&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[0].program_name" /&gt;&lt;/th&gt;
      &lt;/tr&gt;
   &lt;tr&gt; 
                  &lt;th&gt;&lt;form:input path="programs[1].program_id" /&gt;&lt;/th&gt;
                   &lt;th&gt; &lt;form:input path="programs[1].date" id="datepick" class="date-pick"/&gt;
          &lt;script type="text/javascript"&gt;
              datepickr('datepick', { dateFormat: 'Y-m-d' });
          &lt;/script&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[1].type" /&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[1].start" /&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[1].end" /&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[1].location" /&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[1].user_id" /&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;form:input path="programs[1].program_name" /&gt;&lt;/th&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;br/&gt;
  &lt;input type="submit" value="Insert User" /&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>Program</p>
  
  <pre><code>    package net.roseindia.model;
  
  
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = "program")
  public class Programs {
  
  
  
  
      @Id
      @Column(name = "Program_Id")
      private int program_id;
      @Column(name = "Date")
      private String date;
      @Column(name = "Duty_Type")
      private String type;
      @Column(name = "Duty_Start_Time")
      private String start;
      @Column(name = "Duty_End_Time")
      private String end;
      @Column(name = "Location")
      private String location;
      @Column(name = "User_Id")
      private int user_id;
      @Column(name = "Program_Name")
      private String program_name;
  
  
      public int getProgram_id() {
          return program_id;
      }
  
  
      public void setProgram_id(int program_id) {
          this.program_id = program_id;
      }
  
  
      public String getDate() {
          return date;
      }
  
  
      public void setDate(String date) {
          this.date = date;
      }
  
  
      public String getType() {
          return type;
      }
  
  
      public void setType(String type) {
          this.type = type;
      }
  
  
  
  
      public String getStart() {
          return start;
      }
  
  
      public void setStart(String start) {
          this.start = start;
      }
  
  
      public String getEnd() {
          return end;
      }
  
  
      public void setEnd(String end) {
          this.end = end;
      }
  
  
      public String getLocation() {
          return location;
      }
  
  
      public void setLocation(String location) {
          this.location = location;
      }
  
  
      public int getUser_id() {
          return user_id;
      }
  
  
      public void setUser_id(int user_id) {
          this.user_id = user_id;
      }
  
  
      public String getProgram_name() {
          return program_name;
      }
  
  
      public void setProgram_name(String program_name) {
          this.program_name = program_name;
      }
  
  
      public Programs() { 
  
      }
  
  
  
  
  
  }
  </code></pre>
  
  <p>ProgramForm</p>
  
  <pre><code>package net.roseindia.model;
  
  import java.util.List;
  
  public class ProgramForm {
  
  
  
      private List&lt;Programs&gt; programs;
  
      public List&lt;Programs&gt; getPrograms() {
          return programs;
      }
  
      public void setPrograms(List&lt;Programs&gt; programs) {
          this.programs = programs;
      }
  
  
  }
  </code></pre>
  
  <p>When i push the button to save this to programs nothing inserted in the database, what i am doing wrong? </p>