title: Creating ArrayList through Form submitting ( Thymeleaf + Spring MVC )
body: <p>i wanted to know, how Lists are getting binded in Spring...and how to access them in Thymeleaf.
  With and without WrapperClass
  How could achieve adding single / multiple objects through an form to an ArrayList or normal Array..</p>
  
  <p>I would be very thankful for an explanation.</p>
  
  <p>Thats what i have tried:
  Form</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form action="#" th:action="@{/tests}" th:object="${features}" method="post"&gt;
  
  
  
          &lt;input type="text" th:field="*{featureArrayList[0].name}"/&gt;
      &lt;input type="text" th:field="*{featureArrayList[1].name}"/&gt;
  
  
  
  
      &lt;p&gt;&lt;input type="submit" value="Submit" /&gt; &lt;input type="reset" value="Reset" /&gt;&lt;/p&gt;
  &lt;/form&gt;
  
  </code></pre>
  
  <p>Wrapper Class </p>
  
  <pre class="lang-java prettyprint-override"><code>  ArrayList&lt;Feature&gt; featureArrayList = new ArrayList&lt;Feature&gt;();
  
      public FeatureWrapper() {
  
      }
  
      public ArrayList&lt;Feature&gt; getFeatureArrayList() {
          return featureArrayList;
      }
  
      public void setFeatureArrayList(ArrayList&lt;Feature&gt; featureArrayList) {
          this.featureArrayList = featureArrayList;
      }
  </code></pre>
  
  <p>Model:</p>
  
  <pre class="lang-java prettyprint-override"><code>   private String name;
  
      public Feature(String name) {
          this.name = name;
      }
  
      public Feature() {
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  </code></pre>
  
  <p>Controller</p>
  
  <pre class="lang-java prettyprint-override"><code>
        @GetMapping("/tests")
      public String showForm(Model model)
      {
          FeatureWrapper featureWrapper = new FeatureWrapper();
  
          model.addAttribute("features",  featureWrapper);
          return "Feature";
      }
      @PostMapping("/tests")
      public String proceedForm(@ModelAttribute("features") FeatureWrapper features,Model model)
      {
         for(Feature feature: features.getFeatureArrayList())
         {
             System.out.println(feature.getName());
             System.out.println(features.getFeatureArrayList().size());
         }
  
          return "Feature";
      }
  </code></pre>
  
  <p>Edit1:
  Now its working with an Wrapper Class and using static Indexes...
  How would i achieve this without a wrapper class , i read much about the EL expression <strong>${var.index}</strong> , but how is this working ? 
  And how should i use this to dynamically add my Objects.
  Edit2: Now im able to add single objects , and multiple objects to the list, but im not using any EL Expression, so i wanted to know 
  when would i need to use something like this:</p>
  
  <pre class="lang-html prettyprint-override"><code> &lt;div th:each="feature,stat:*{featureArrayList}"&gt;
          &lt;input  id="myInput" type="text" th:field="*{featureArrayList[__${stat.index}__].name}"/&gt;
      &lt;/div&gt;
  </code></pre>