title: Form Table with java, thymeleaf and spring mvc
body: <p>My problem:</p>
  
  <p>In my method save, i receive a inscriptionsForm but it contains is null; inscriptionsForm.getInscriptions() == null, Why?</p>
  
  <p>I have tried multiple ways such as: </p>
  
  <pre><code>    &lt;div th:each="inscription, stat : *{inscriptions}"&gt;
      &lt;div th:each="inscription, stat : *{inscriptionsForm.inscriptions}"&gt;
      &lt;div th:each="inscription : *{inscriptionsForm.inscriptions}"&gt;
  </code></pre>
  
  <p>but is always null.</p>
  
  <p>My code:</p>
  
  <pre><code>    /** The Class TrainingTypeListController. */
      @Controller
      public class InscriptionListController {
  
          /** The Constant TRAINING_VIEW_NAME. */                        
          private static final String TRAINING_VIEW_NAME = "training/inscriptions";
  
          /** The TrainingTypeService. */
          @Autowired
          private TrainingService trainingService;
  
          /** The trainingTypes. */
          public static List&lt;Inscription&gt; inscriptions;
  
          /** The trainingTypes. */
          private Training training;
  
          /**
           * Instantiates a new training Controller.
           */
          public InscriptionListController() {
              // Default empty constructor.
          }
  
          /**
           * Show TrainingType List.
           *
           * @param model
           *            the model
           * @return the string the view
           */
  
          @RequestMapping(value = "trainingList/inscriptions/{trainingId}")
          public String trainings(@PathVariable Long trainingId, Model model) {
  
              //List of inscriptions
              inscriptions = trainingService.getInscriptionsByTrainingId(trainingId);
              model.addAttribute("inscriptions", inscriptions);
  
              training = trainingService.findById(trainingId);
              model.addAttribute("training", training);
  
  
              InscriptionsForm inscriptionsForm = new InscriptionsForm();
              inscriptionsForm.setInscriptions(inscriptions);
              model.addAttribute(inscriptionsForm);
              //System.out.println("-&gt; " + inscriptionsForm);
              //System.out.println("-&gt; " + inscriptionsForm.getInscriptions());
  
              return TRAINING_VIEW_NAME;
          }
  
          /**
           * List of  inscriptions.
           *
           * @return List&lt;Inscription&gt;
           */
          @ModelAttribute("inscriptions")
          public List&lt;Inscription&gt; inscriptions() {
              return  inscriptions;
          }
  
          /**
           * List of  inscriptions.
           *
           * @return Inscription
           */
          @ModelAttribute("training")
          public Training training() {
              return training;
          }
  
             @RequestMapping(value = "trainingList/inscriptions/save", method = RequestMethod.POST)
              public String save(@Valid @ModelAttribute InscriptionsForm inscriptionsForm) {
                  System.out.println("formulario:       " + inscriptionsForm);
                  System.out.println("inscriptionsForm: " + inscriptionsForm.getInscriptions());
                  List&lt;Inscription&gt; inscriptions = inscriptionsForm.getInscriptions();
  
  
                  System.out.println("****\n " + InscriptionListController.inscriptions);
                  System.out.println("name: " + InscriptionListController.inscriptions.get(0).getAccount().getName());
                  System.out.println("note: " + InscriptionListController.inscriptions.get(0).getNote());
  
                  if(null != inscriptions &amp;&amp; inscriptions.size() &gt; 0) {
                      InscriptionListController.inscriptions = inscriptions;
                      for (Inscription inscription : inscriptions) {
                          System.out.printf("%s \t %s \n", inscription.getAccount().getName());
                      }
                  }
                  System.out.println("---------------------------------------------- ");
                  return "redirect:/trainingList";
              }
  
      }
  </code></pre>
  
  <p>FORM</p>
  
  <pre><code>/** The InscriptionsForm. */
  public class InscriptionsForm {
  
      /** The Inscription List. */
      private List&lt;Inscription&gt; inscriptions;
  
      /** The getInscriptions. */
      public List&lt;Inscription&gt; getInscriptions() {
          return inscriptions;
      }
  
      /** The setInscriptions. */
      public void setInscriptions(List&lt;Inscription&gt; inscriptions) {
          this.inscriptions = inscriptions;
      }
  }
  </code></pre>
  
  <p>HTML</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns:th="http://www.thymeleaf.org"
      xmlns:tiles="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"&gt;
  &lt;head&gt;
  &lt;title th:text="#{inscriptions.title}"&gt;&lt;/title&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;link href="../../../resources/css/bootstrap.min.css" rel="stylesheet"
      media="screen" th:href="@{/resources/css/bootstrap.min.css}" /&gt;
  &lt;link href="../../../resources/css/core.css" rel="stylesheet"
      media="screen" th:href="@{/resources/css/core.css}" /&gt;
  &lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
  &lt;script src="../../../resources/js/bootstrap.min.js"
      th:src="@{/resources/js/bootstrap.min.js}"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
      &lt;!-- Generic Header --&gt;
      &lt;div th:replace="fragments/header :: header(active='training')"&gt;&amp;nbsp;&lt;/div&gt;
  
  
      &lt;fieldset&gt;
  
          &lt;!-- Verify if exits Inscriptions --&gt;
          &lt;div th:unless="${#lists.isEmpty(inscriptionsForm.inscriptions)}"&gt;
  
              &lt;h2 class="text-center"
                  th:text="#{inscription.inscriptionlist}+${training.name}"&gt;List
                  of Training Types&lt;/h2&gt;
  
  
              &lt;!-- Table List of Inscriptions --&gt;
              &lt;form method="post" th:action="@{/trainingList/inscriptions/save}"
                  th:object="${inscriptionsForm}"&gt;
                  &lt;table class="table table-striped table-hover form-narrow "&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th th:text="#{name}"&gt;Name&lt;/th&gt;
                              &lt;th th:text="#{inscription.attend}"&gt;Attend&lt;/th&gt;
                              &lt;th th:text="#{inscription.note}"&gt;Note&lt;/th&gt;
                              &lt;th th:text="#{inscription.pass}"&gt;Pass&lt;/th&gt;
                              &lt;th th:text="#{inscription.unsubscribe}"&gt;Baja&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody&gt;
  
  
                          &lt;!-- Table Inscriptions --&gt;
                          &lt;tr th:each="inscription : ${inscriptionsForm.inscriptions}"&gt;
                              &lt;td th:text="${inscription.account.name}"&gt;name&lt;/td&gt;
                              &lt;td&gt;&lt;input type="checkbox"
                                  th:checked="${inscription.attend}"
                                  th:title="#{inscription.infoAttend}" /&gt;&lt;/td&gt;
  
  
                              &lt;td&gt;&lt;textarea id="note" th:text="${inscription.note}"
                                      th:placeholder="#{note}" rows="3" cols="40"&gt; Note &lt;/textarea&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;input type="checkbox" th:checked="${inscription.pass}"
                                  th:title="#{inscription.infoPass}" /&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;input type="checkbox"
                                  th:checked="${inscription.unsubscribe}"
                                  th:title="#{inscription.infoUnsubscribe}" /&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/tbody&gt;
                  &lt;/table&gt;
                  &lt;!-- Button Modify, visible if a checkbox enable is pressed --&gt;
                  &lt;div class="text-center"&gt;
                      &lt;button type="submit" class="btn btn-success btn-lg"
                          th:text="#{inscription.confirm}"&gt;Confirm&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/form&gt;
          &lt;/div&gt;
  
      &lt;/fieldset&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>