title: Failed parsing Thymeleaf template when validating form with Spring Bean Validation API
body: <p>I am following this book "Spring In Action 5th Edition" example, but having this error whenever validation on form input found something invalid.</p>
  
  <p>error:</p>
  
  <pre><code>Whitelabel Error Page
  This application has no explicit mapping for /error, so you are seeing this as a fallback.
  
  Sun Oct 27 17:26:07 SGT 2019
  There was an unexpected error (type=Internal Server Error, status=500).
  An error happened during template parsing (template: "class path resource [templates/design.html]")
  org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/design.html]")
      at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
      at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100)
      at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:666)
      at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098)
      at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072)
      at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:362)
      at org.thymeleaf.spring5.view.ThymeleafView.render(ThymeleafView.java:189)
      at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1371)
      at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1117)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1056)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:118)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      at java.lang.Thread.run(Thread.java:748)
  Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "design" - line 59, col 20)
      at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
      at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
      at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
      ... 52 more
  Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "design" - line 59, col 20)
      at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117)
      at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95)
      at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633)
      at org.thymeleaf.engine.ProcessorTemplateHandler.handleStandaloneElement(ProcessorTemplateHandler.java:918)
      at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleStandaloneElementEnd(TemplateHandlerAdapterMarkupHandler.java:260)
      at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:256)
      at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleStandaloneElementEnd(OutputExpressionInlinePreProcessorHandler.java:169)
      at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:104)
      at org.attoparser.HtmlElement.handleStandaloneElementEnd(HtmlElement.java:79)
      at org.attoparser.HtmlMarkupHandler.handleStandaloneElementEnd(HtmlMarkupHandler.java:241)
      at org.attoparser.MarkupEventProcessorHandler.handleStandaloneElementEnd(MarkupEventProcessorHandler.java:327)
      at org.attoparser.ParsingElementMarkupUtil.parseStandaloneElement(ParsingElementMarkupUtil.java:96)
      at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:706)
      at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301)
      ... 54 more
  Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'design' available as request attribute
      at org.springframework.web.servlet.support.BindStatus.&lt;init&gt;(BindStatus.java:153)
      at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903)
      at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227)
      at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306)
      at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253)
      at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227)
      at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174)
      at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
      ... 67 more
  
  </code></pre>
  
  <p>Object been passed to view template:</p>
  
  <pre><code>package tacos;
  
  import java.util.List;
  
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  
  import lombok.Data;
  
  @Data
  public class Taco {
  
      @NotNull
      @Size(min=5, message="Name must be at least 5 characters long")
      private String name;
  
      @NotNull
      @Size(min=2, message="You must choose at least 2 ingredient")
      private List&lt;String&gt; ingredients;
  }
  </code></pre>
  
  <p>Thymeleaf view template:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
  &lt;title&gt;Taco Cloud&lt;/title&gt;
  &lt;link rel="stylesheet" th:href="@{/styles.css}" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Design your taco!&lt;/h1&gt;
  &lt;img th:src="@{/images/TacoCloud.png}"/&gt;
  &lt;form method="POST" th:object="${design}"&gt;
  &lt;div class="grid"&gt;
  &lt;div class="ingredient-group" id="wraps"&gt;
  &lt;h3&gt;Designate your wrap:&lt;/h3&gt;
  &lt;div th:each="ingredient : ${wrap}"&gt;
  &lt;input name="ingredients" type="checkbox" th:value="${ingredient.id}"
  /&gt;
  &lt;span th:text="${ingredient.name}"&gt;INGREDIENT&lt;/span&gt;&lt;br/&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="ingredient-group" id="proteins"&gt;
  &lt;h3&gt;Pick your protein:&lt;/h3&gt;
  &lt;div th:each="ingredient : ${protein}"&gt;
  &lt;input name="ingredients" type="checkbox" th:value="${ingredient.id}"
  /&gt;
  &lt;span th:text="${ingredient.name}"&gt;INGREDIENT&lt;/span&gt;&lt;br/&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="ingredient-group" id="cheeses"&gt;
  &lt;h3&gt;Choose your cheese:&lt;/h3&gt;
  &lt;div th:each="ingredient : ${cheese}"&gt;
  &lt;input name="ingredients" type="checkbox" th:value="${ingredient.id}"
  /&gt;
  &lt;span th:text="${ingredient.name}"&gt;INGREDIENT&lt;/span&gt;&lt;br/&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="ingredient-group" id="veggies"&gt;
  &lt;h3&gt;Determine your veggies:&lt;/h3&gt;
  &lt;div th:each="ingredient : ${veggies}"&gt;
  &lt;input name="ingredients" type="checkbox" th:value="${ingredient.id}"
  /&gt;
  &lt;span th:text="${ingredient.name}"&gt;INGREDIENT&lt;/span&gt;&lt;br/&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="ingredient-group" id="sauces"&gt;
  &lt;h3&gt;Select your sauce:&lt;/h3&gt;
  &lt;div th:each="ingredient : ${sauce}"&gt;
  &lt;input name="ingredients" type="checkbox" th:value="${ingredient.id}"
  /&gt;
  &lt;span th:text="${ingredient.name}"&gt;INGREDIENT&lt;/span&gt;&lt;br/&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div&gt;
  &lt;h3&gt;Name your taco creation:&lt;/h3&gt;
  &lt;input type="text" th:field="*{name}"/&gt;
  &lt;span class="validationError"
                  th:if="${#fields.hasErrors('name')}"
                  th:errors="*{name}"&gt;Name Error&lt;/span&gt;
  &lt;br/&gt;
  &lt;button&gt;Submit your taco&lt;/button&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Controller display form method:</p>
  
  <pre><code>    @GetMapping
      public String showDesignForm(Model model)
      {
          List&lt;Ingredient&gt; ingredients = Arrays.asList(
                  new Ingredient("FLTO", "Flour Tortilla", Type.WRAP),
                  new Ingredient("COTO", "Corn Tortilla", Type.WRAP),
                  new Ingredient("GRBF", "Ground Beef", Type.PROTEIN),
                  new Ingredient("CARN", "Carnitas", Type.PROTEIN),
                  new Ingredient("TMTO", "Diced Tomatoes", Type.VEGGIES),
                  new Ingredient("LETC", "Lettuce", Type.VEGGIES),
                  new Ingredient("CHED", "Cheddar", Type.CHEESE),
                  new Ingredient("JACK", "Monterrey Jack", Type.CHEESE),
                  new Ingredient("SLSA", "Salsa", Type.SAUCE),
                  new Ingredient("SRCR", "Sour Cream", Type.SAUCE)
                  );
  
          Type[] types = Ingredient.Type.values();
          for (Type type : types)
          {
              model.addAttribute(type.toString().toLowerCase(), 
                      filterByType(ingredients, type));
          }
  
          model.addAttribute("design", new Taco());
  
          return "design";
      }
  </code></pre>
  
  <p>Controller process form method:</p>
  
  <pre><code>    @PostMapping
      public String processDesign(@Valid Taco taco, Errors errors)
      {
          if (errors.hasErrors())
          {
              return "design";
          }
  
          // Save the taco design...
          // We will do this in chapter 3
          log.info("Processing design: " + taco);
  
          return "redirect:/orders/current";
      }
  </code></pre>
  
  <p>I have no issue in displaying the form. All input fields are well received and processed. But whenever there is validation errors, and <code>process form method</code> call back to the form page "design", the form  failed to parse with above mentioned errors.<br/><br/>
  I had tried:<br/>1. to disable validation on the Taco.name field;<br/>2. to remove the <code>&lt;span&gt;</code> which displays the name field errors. <br/>But none of them work.<br/><br/>
  Thanks in advance for your help.</p>