title: How to validate a form with binding result?
body: <p>I have a simple form to save an User and I can't get it to show the error messages</p>
  
  <p>I have the exact same structure for saving "Customer" and it works, but when I try to replicate it to User It doesn't work</p>
  
  <p>My log error:</p>
  
  <blockquote>
    <p>2019-08-21 17:07:14.521  WARN 11332 --- [nio-8080-exec-8]
    .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused
    by handler execution: org.springframework.validation.BindException:
    org.springframework.validation.BeanPropertyBindingResult: 1 errors
    Field error in object 'user' on field 'password': rejected value
    [123]; codes
    [Size.user.password,Size.password,Size.java.lang.String,Size];
    arguments
    [org.springframework.context.support.DefaultMessageSourceResolvable:
    codes [user.password,password]; arguments []; default message
    [password],2147483647,6]; default message [A senha deve conter pelo
    menos 6 caracteres.]</p>
  </blockquote>
  
  <p>User controllers:</p>
  
  <pre><code>@GetMapping("/{customerId}/createUser")
  public ModelAndView userForm(@PathVariable(value = "customerId", required 
  = false) Long customerId,
          @RequestParam(value = "userId", required = false) Long userId, 
  Model model) {
  
      Authentication authentication = 
  SecurityContextHolder.getContext().getAuthentication();
  
      Optional&lt;Users&gt; authenticatedUserOptional = 
  userRepository.findByEmail(authentication.getName());
      model.addAttribute("userLogedIsAdmin", 
  authenticatedUserOptional.get().getIsAdmin());
  
      if (authentication == null || !authentication.isAuthenticated()) {
          ModelAndView mv = new ModelAndView("accessDenied");
          return mv;
      }
  
      if (!authenticatedUserOptional.isPresent()) {
          ModelAndView mv = new ModelAndView("accessDenied");
          return mv;
      }
  
      if (customerId != null) {
  
          Optional&lt;Customers&gt; customerOptional = 
  customerRepository.findById(customerId);
          Customers customer = customerOptional.get();
  
          model.addAttribute("customer", customer);
  
          if (userId != null) {
              Users existingUser = userRepository.findById(userId).get();
              if (existingUser.getEnabled()) {
                  existingUser.setUserStatus(UserStatus.ATIVO);
              } else {
                  existingUser.setUserStatus(UserStatus.INATIVO);
              }
              model.addAttribute("user", existingUser);
          } else {
              model.addAttribute("user", new Users());
          }
  
          ModelAndView mv = new ModelAndView("customerNewUser");
          return mv;
      } else {
          ModelAndView mv = new ModelAndView("accessDenied");
          return mv;
      }
  }
  
  @PostMapping("/{customerId}/createUser")
  public ModelAndView saveUser(@PathVariable(value = "customerId", required 
  = true) Long customerId,
          @ModelAttribute(name = "user") @Valid Users user, 
  RedirectAttributes redirectAttributes,
          BindingResult bindingResult) {
  
      if (bindingResult.hasErrors()) {
          return userForm(customerId, user.getId(), new Model() {
  
              @Override
              public Model mergeAttributes(Map&lt;String, ?&gt; attributes) {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public boolean containsAttribute(String attributeName) {
                  // TODO Auto-generated method stub
                  return false;
              }
  
              @Override
              public Map&lt;String, Object&gt; asMap() {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public Model addAttribute(String attributeName, Object 
  attributeValue) {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public Model addAttribute(Object attributeValue) {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public Model addAllAttributes(Map&lt;String, ?&gt; attributes) {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public Model addAllAttributes(Collection&lt;?&gt; attributeValues) 
  {
                  // TODO Auto-generated method stub
                  return null;
              }
          });
      }
  
      // Encrypt password
      if (user.getPassword().equals(user.getMatchPassword())) {
          user.setPassword(encoder.encode(user.getPassword()));
          user.setCustomerId(customerId);
          user.setEventDescription("User Admin creation");
  
          Users returnedUser = userService.save(user);
  
          List&lt;Authorities&gt; authorities = new ArrayList&lt;Authorities&gt;();
          Authorities auth = new Authorities(new 
  AuthoritiesPK(returnedUser.getId(), "ROLE_CLI_ADM"), returnedUser,
                  "ROLE_CLI_ADM");
          authorities.add(auth);
          returnedUser.setAuthorities(authorities);
          returnedUser.setEventDescription("Add Admin role");
  
          for (int i = 0; i &lt; returnedUser.getAuthorities().size(); i++) {
              authorityService.save(returnedUser.getAuthorities().get(i));
          }
          userService.save(returnedUser);
          ModelAndView mv = new ModelAndView("redirect:/customers/" + 
  customerId);
          return mv;
      } else {
          ModelAndView mv = new ModelAndView("accessDenied");
          return mv;
      }
  }
  </code></pre>
  
  <p>form html:</p>
  
  <pre><code>&lt;div class="card mb-3"&gt;
  
                  &lt;div class="card-header"
                      th:text="${user?.id} ? #{editUser} : #{newUser}"&gt;
                      &lt;i class="fas fa-table"&gt;&lt;/i&gt;
                  &lt;/div&gt;
                  &lt;div class="card-body"&gt;
                      &lt;form
                          th:action="@{${user?.id} ? '/customers/' + ${customer.id} + '/createUser/' + ${user.id} : '/customers/' + ${customer.id} + '/createUser/'}"
                          th:object="${user}" action="#" method="post"&gt;
  
                          &lt;div class="alert alert-danger" th:if="${#fields.hasAnyErrors()}"&gt;
                              &lt;div th:each="detailedError : ${#fields.detailedErrors()}"&gt;
                                  &lt;span th:text="${detailedError.message}"&gt;&lt;/span&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group"&gt;
                              &lt;div class="form-row"&gt;
                                  &lt;div class="col-md-5"&gt;
                                      &lt;label class="text-right label-control"
                                          th:text="#{firstname} + ':'"&gt;Firstname:&lt;/label&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-4"&gt;
                                      &lt;input type="text" id="firstname" name="firstname"
                                          th:value="${user?.firstname} ? ${user?.firstname} : ''"
                                          class="form-control" th:placeholder="#{firstname}"
                                          required="required" autofocus="autofocus"
                                          th:field="*{firstname}" /&gt; 
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;div class="form-row"&gt;
                                  &lt;div class="col-md-5"&gt;
                                      &lt;label class="text-right label-control"
                                          th:text="#{surname} + ':'"&gt;Surname:&lt;/label&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-4"&gt;
                                      &lt;input type="text" id="surname" name="surname"
                                          th:value="${user?.surname} ? ${user?.surname} : ''"
                                          class="form-control" th:placeholder="#{surname}"
                                          autofocus="autofocus" /&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;div class="form-row"&gt;
                                  &lt;div class="col-md-5"&gt;
                                      &lt;label class="text-right label-control"
                                          th:text="#{email} + ':'"&gt;Email:&lt;/label&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-4"&gt;
                                      &lt;input th:placeholder="#{email}" required="required"
                                          autofocus="autofocus" id="email" class="form-control"
                                          type="text" th:value="${user?.email} ? ${user?.email} : ''"
                                          name="email" th:field="*{email}" /&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group" th:if="!${user?.id}"&gt;
                              &lt;div class="form-row"&gt;
                                  &lt;div class="col-md-5"&gt;
                                      &lt;label class="text-right label-control"
                                          th:text="#{password} + ':'"&gt;Password:&lt;/label&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-4"&gt;
                                      &lt;input type="password" id="password" name="password"
                                          class="form-control" th:placeholder="#{password}"
                                          required="required" autofocus="autofocus"
                                          th:field="*{password}" /&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group" th:if="!${user?.id}"&gt;
                              &lt;div class="form-row"&gt;
                                  &lt;div class="col-md-5"&gt;
                                      &lt;label class="text-right label-control"
                                          th:text="#{passwordConfirmation} + ':'"&gt;Password
                                          confirmation:&lt;/label&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-4"&gt;
                                      &lt;input type="password" id="matchPassword" name="matchPassword"
                                          class="form-control" th:placeholder="#{password}"
                                          required="required" autofocus="autofocus"
                                          th:field="*{matchPassword}" /&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
  
                          &lt;div class="form-group" th:if="${user?.id}"&gt;
                              &lt;div class="form-row"&gt;
                                  &lt;div class="col-md-5"&gt;
                                      &lt;label class="text-right label-control"
                                          th:text="#{userStatus} + ':'"&gt;Status:&lt;/label&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-md-3"&gt;
                                      &lt;select class="form-control form-control" id="userStatus"
                                          name="userStatus"&gt;
                                          &lt;option
                                              th:each="userStatus : ${T(br.com.macrosul.stetho.entity.UserStatus).values()}"
                                              th:text="${userStatus}" th:value="${userStatus}"
                                              th:selected="${user.userStatus} eq ${userStatus}"&gt;&lt;/option&gt;
                                      &lt;/select&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group" id="saveDiv"&gt;
                              &lt;div class="form-row"&gt;
                                  &lt;div class="col-md-5"&gt;&lt;/div&gt;
                                  &lt;div class="col-md-2"&gt;
                                      &lt;a class="btn-nounderline" href="#"&gt; &lt;input type="submit"
                                          class="btn btn-md btn-block" value="Save"
                                          th:value="${user?.id} ? #{updateUser} : #{save}" id="save" /&gt;
                                      &lt;/a&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>part of my model:</p>
  
  <pre><code>@Entity
  public class Users extends BaseEntity {
  
  private static final long serialVersionUID = -1667698094711992210L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = 
  "users_seq")
  @SequenceGenerator(name = "users_seq", sequenceName = "users_seq", 
  allocationSize = 50, initialValue = 1)
  @JsonProperty(access = Access.READ_ONLY)
  private Long id;
  @NotBlank(message = "E-mail não pode estar em branco.")
  @NotNull(message = "E-mail deve ser informado.")
  @Email(message = "Formato inválido de E-mail.")
  @Column(nullable = false, unique = true)
  private String email;
  @JsonProperty(access = Access.WRITE_ONLY)
  @Size(min=6, message="A senha deve conter pelo menos 6 caracteres.")
  @NotNull(message = "A senha deve ser informada.")
  @NotBlank(message = "A senha não pode estar em branco.")
  @NotEmpty(message = "A senha não pode estar vazia.")
  @Column(nullable = false)
  private String password;
  @JsonIgnore
  @Transient
  private String matchPassword;
  @JsonIgnore
  @Column(nullable = false)
  private Boolean enabled = true;
  @NotNull(message = "O nome deve ser informada.")
  @NotBlank(message = "O nome não pode estar em branco.")
  @NotEmpty(message = "O nome não pode estar vazia.")
  @Column(nullable = false)
  private String firstname;
  private String surname;
  @Column(nullable = true)
  private Long customerId;
  @JsonIgnore
  @Transient
  private Boolean isAdmin;
  @JsonIgnore
  @OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
  private List&lt;Authorities&gt; authorities = new ArrayList&lt;&gt;();
  @Enumerated(EnumType.STRING)
  @Transient
  private UserStatus userStatus;
  }
  </code></pre>
  
  <p>I simply can't understand why it does not show the error message, I'm pretty sure what's logged is not en error itself... Any help would be appreciated!</p>