title: Thymeleaf and #fields.hasErrors
body: <p>I have this assignment I am working on for school.  Using SpringMVC, Hibernate JPA, and Thymeleaf.  The following code below involves a specific attribute called " stringGrade ".  I want to validate the input in that field using Hibernate Validator.  I cannot seem to get Thymeleaf to read the expression.  The arrayList that is looped in the view has a name attribute of " deliverables[0].stringGrade " and so on depending on how many there are.  I have tried using " deliverables[<strong>${stat.index}</strong>].name " and this causes Thymeleaf to fail with this error:</p>
  
  <p>HTTP Status 500 - Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#fields.hasErrors('deliverables[0].stringGrade')" (menuItems/inputGrades:33)</p>
  
  <p>All I want to do is have Thymeleaf be able to read the value using #fields.HasErrors and #fields.error. Below is the code that is relevant:</p>
  
  <p>GradeCalculator Model:</p>
  
  <pre><code>public class GradeCalculator {
  
  private ArrayList&lt;Deliverable&gt; deliverables;
  </code></pre>
  
  <p>Deliverable Model:</p>
  
  <pre><code>@Entity
  @Table(name="Deliverables")
  public class Deliverable implements Serializable {
  
  
  @NotEmpty(message = "Required")
  @Size(min = 1, max = 100, message = "Must be between 1 and 100")
  @Digits(integer = 3, fraction = 0, message = "Must be a numeric value")
  private String stringGrade; // String version of the grade ( Used for view input fields )
  </code></pre>
  
  <p>ThymeLeaf View: </p>
  
  <pre><code>&lt;form th:object="${gradeCalculator}" action="#" th:action="@{/process/inputGrades}" method="POST" class="form-horizontal" role="form"&gt;
  
      &lt;div th:each="deliverable,stat : ${grades.deliverables}"&gt;
          &lt;div class="form-group"&gt;
              &lt;p&gt;Deliverable Name&lt;span th:text="${grades.deliverables[__${stat.index}__].name}" name="name" id="name" class="badge tab-space"&gt;&lt;/span&gt;&lt;/p&gt;
              &lt;p&gt;Deliverable Weight&lt;span th:text="${grades.deliverables[__${stat.index}__].weight}" name="weight" id="weight" class="badge tab-space"&gt;&lt;/span&gt;&lt;/p&gt;
  
              &lt;h3&gt;&lt;span class="label"&gt;Grade:&lt;/span&gt;&lt;/h3&gt;
  
              &lt;input type="text" th:field="${grades.deliverables[__${stat.index}__].stringGrade}" class="form-control" /&gt;
              &lt;ul class="help-inline" th:if="${#fields.hasErrors('deliverables[__${stat.index}__].stringGrade')}"&gt;
                  &lt;li class="error" th:each="err : ${#fields.errors('deliverables[__${stat.index}__].stringGrade')}" th:text="${err}"&gt;Input is incorrect&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;div class="text-center col-sm-10 col-sm-offset-2 col-md-4 col-md-offset-4"&gt;
                  &lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>