title: How to handle bindingresult errors in mustache springboot
body: <p>I am learning mustache with springboot.
  I am getting error page while handling the binding result.</p>
  <p>My controller class method to handle request:</p>
  <pre><code>@PostMapping(&quot;/registerUser&quot;)
      public String createNewBuyer(@ModelAttribute(&quot;user&quot;) @Valid MyUser user, final Model model, final BindingResult result) {
          if (result.hasErrors()) {
              model.addAttribute(&quot;user&quot;, user);
              return &quot;page-login-register&quot;;
          }
          String error = userService.checkIfUserExists(user);
          if (error != null) {
              model.addAttribute(&quot;registerError&quot;, error);
          } else {
              userService.saveUser(user);
          }
          return &quot;page-login-register&quot;;
      }
  </code></pre>
  <p>POJO class to map request variable and validate</p>
  <pre><code>@Data
  public class MyUser implements Serializable {
  
      private Integer userId;
      @NotEmpty(message = &quot;registration.validation.userName&quot;)
      @Size(min = 3, message = &quot;minimum size of username should be 3&quot;)
      private String userName;
      @NotEmpty(message = &quot;registration.validation.firstName&quot;)
      private String firstName;
      @NotEmpty(message = &quot;registration.validation.lastName&quot;)
      private String lastName;
      @NotEmpty(message = &quot;registration.validation.email&quot;)
      @Size(min = 5, max = 64, message = &quot;Please enter a valid email&quot;)
      private String email;
      @NotEmpty(message = &quot;registration.validation.password&quot;)
      @Size(min = 5, max = 24, message = &quot;Please enter a valid password.&quot;)
      private String password;
      private String confirmPassword;
      @NotEmpty(message = &quot;registration.validation.phoneNumber&quot;)
      @Size(min = 10, message = &quot;Please enter valid phone Number.&quot;)
      private String phoneNumber;
  }
  </code></pre>
  <p>Html code to submit request and show error</p>
  <pre><code>{{#registerError}}
                                          &lt;p class=&quot;mb-50 font-sm text-danger&quot;&gt;
                                              {{registerError}}
                                          &lt;/p&gt;
                                          {{/registerError}}
                                          {{#user}}
                                          &lt;form method=&quot;post&quot; action=&quot;/registerUser&quot; name=&quot;user&quot;&gt;
                                              {{#_csrf}}
                                              &lt;input type=&quot;hidden&quot; name=&quot;{{parameterName}}&quot; value=&quot;{{token}}&quot;/&gt;
                                              {{/_csrf}}
                                              &lt;div class=&quot;form-group&quot;&gt;
                                                  &lt;input type=&quot;text&quot; required=&quot;&quot; name=&quot;userName&quot; value=&quot;{{#userName}}{{userName}}{{/userName}}&quot; placeholder=&quot;Username&quot;&gt;
                                              &lt;/div&gt;
                                               &lt;div class=&quot;form-group&quot;&gt;
                                                  &lt;input type=&quot;text&quot; required=&quot;&quot; name=&quot;firstName&quot; placeholder=&quot;First Name&quot; value=&quot;{{#firstName}}{{firstName}}{{/firstName}}&quot;&gt;
                                              &lt;/div&gt;
                                               &lt;div class=&quot;form-group&quot;&gt;
                                                  &lt;input type=&quot;text&quot; required=&quot;&quot; name=&quot;lastName&quot; placeholder=&quot;Last Name&quot; value=&quot;{{#lastName}}{{lastName}}{{/lastName}}&quot;&gt;
                                              &lt;/div&gt;
                                              &lt;div class=&quot;form-group&quot;&gt;
                                                  &lt;input type=&quot;email&quot; required=&quot;&quot; name=&quot;email&quot; placeholder=&quot;Email&quot; value=&quot;{{#email}}{{email}}{{/email}}&quot;&gt;
                                              &lt;/div&gt;
                                              &lt;div class=&quot;form-group&quot;&gt;
                                                  &lt;input type=&quot;phone number&quot; required=&quot;&quot; name=&quot;phoneNumber&quot; placeholder=&quot;Phone Number&quot; value=&quot;{{#phoneNumber}}{{phoneNumber}}{{/phoneNumber}}&quot;&gt;
                                              &lt;/div&gt;
                                              &lt;div class=&quot;form-group&quot;&gt;
                                                  &lt;input required=&quot;&quot; type=&quot;password&quot; name=&quot;password&quot; placeholder=&quot;Password&quot;&gt;
                                              &lt;/div&gt;
                                              &lt;div class=&quot;form-group&quot;&gt;
                                                  &lt;input required=&quot;&quot; type=&quot;password&quot; name=&quot;confirmPassword&quot; placeholder=&quot;Confirm password&quot;&gt;
                                              &lt;/div&gt;
                                          &lt;div class=&quot;form-group&quot;&gt;
                                                  &lt;button type=&quot;submit&quot; class=&quot;btn btn-fill-out btn-block hover-up&quot; name=&quot;login&quot;&gt;Submit &amp;amp; Register&lt;/button&gt;
                                              &lt;/div&gt;
                                          &lt;/form&gt;
                                          {{/user}}
  </code></pre>
  <p>When I am sending request with 3 digit password am not able to show same page and show the errors. I can achieve to handle this by adding validation into controller instead of pojo class but thats not good practice. I need help how to handle bindingresult exception and show in same page(using mustache).</p>
  <p>Update:</p>
  <p>I found some article where they said about order of parameter of method in controller. i.e. while writing parameters in a method write bindingresult class just after pojo class. like:</p>
  <pre><code>public String createNewBuyer(@ModelAttribute(&quot;user&quot;) @Valid MyUser user, final BindingResult result, final Model model) {
  </code></pre>
  <p>but now how to show them in mustache page just like thymeleaf handles. am working on it but if anybody have idea please help me.</p>