title: Javax @Valid annotation doesn't work as expected
body: <p>I have a for with object creation. When I trying to create it and validate - I receiving an error, but not on the UI side, as expected. Don't understand why.</p>
  <p>Here is my html code:</p>
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html xmlns:th=&quot;http://www.thymeleaf.org&quot;
        xmlns:layout=&quot;http://www.thymeleaf.org&quot;
        lang=&quot;en&quot;
        layout:decorate=&quot;~{layout/layout}&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot;/&gt;
      &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;/&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;/&gt;
      &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;/&gt;
      &lt;title&gt;Добавить Объект&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;main class=&quot;content-wrapper&quot;&gt;
      &lt;div class=&quot;container-fluid&quot;&gt;
          &lt;form method=&quot;POST&quot; th:action=&quot;@{/admin/objects/add}&quot; th:object=&quot;${objectForm}&quot;&gt;
              &lt;p class=&quot;h4 text-left&quot;&gt;Добавить объект&lt;/p&gt;
              &lt;div class=&quot;form-group col-md-3 offset-md-0&quot;
                   th:classappend=&quot;${#fields.hasErrors('name')}? 'has-error':''&quot;&gt;
                  &lt;label for=&quot;exampleInputName&quot;&gt;&lt;/label&gt;
                  &lt;input name=&quot;username&quot; type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;exampleInputName&quot; required=&quot;required&quot;
                         placeholder=&quot;Название(ручной ввод)&quot;
                         th:field=&quot;*{name}&quot;/&gt;
                  &lt;br/&gt;
                  &lt;p class=&quot;alert alert-danger&quot;
                     th:if=&quot;${#fields.hasErrors('name')}&quot;
                     th:errors=&quot;*{name}&quot;&gt;Validation error&lt;/p&gt;
              &lt;/div&gt;
              &lt;div class=&quot;form-group col-md-1 offset-md-0&quot;&gt;
                  &lt;button type=&quot;submit&quot; class=&quot;btn btn-success offset-md-0 btn-sm active&quot;&gt;Создать&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/main&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>ObjectController:</p>
  <pre><code>@Controller
  @Validated
  @RequestMapping(&quot;/admin/objects&quot;)
  public class ObjectController {
      private static final Logger log = LogManager.getLogger(ObjectController.class);
      private final ObjectsService objectsService;
      private Pageable pageable;
      
      @Autowired
      public ObjectController(ObjectsService objectsService) {
          this.objectsService = objectsService;
      }
  
  @GetMapping(&quot;/add&quot;)
      public String printAddObject(Model model) {
          model.addAttribute(&quot;objectForm&quot;,
                             new Object()
                            );
          return &quot;objects_add&quot;;
      }
      
      @PostMapping(&quot;/add&quot;)
      public String addNewObject(@ModelAttribute(&quot;objectForm&quot;) @Valid Object objectForm,
                                 Model model,
                                 BindingResult bindingResult) {
          if (bindingResult.hasErrors()) {
              System.out.println(&quot;ERROR: &quot; + bindingResult.getAllErrors().toString());
              return &quot;objects_add&quot;;
          }
          if (!objectsService.create(objectForm)) {
              bindingResult.addError(new FieldError(&quot;objectForm&quot;,
                                                    &quot;name&quot;,
                                                    &quot;Объект с таким именем уже существует&quot;
              ));
              return &quot;objects_add&quot;;
          }
          return &quot;redirect:/admin/objects&quot;;
      }
  </code></pre>
  <p>Object class:</p>
  <pre><code>import javax.persistence.*;
  import javax.validation.constraints.NotBlank;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  
  @Entity(name = &quot;objects&quot;)
  public @Data class Object {
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      @Column(name = &quot;object_id&quot;)
      private Long objectId;
      
      @NotNull
      @Size(min = 2)
      @Column(name = &quot;name&quot;)
      private String name; 
  }
  </code></pre>
  <p>When I'm clicking on submit Button and inputing one symbol, I am expecting that UI will show me an error message, but all I can see:</p>
  <p><a href="https://i.stack.imgur.com/BfLA3.png" rel="nofollow noreferrer">Browser error</a></p>
  <p><a href="https://i.stack.imgur.com/ORDv7.png" rel="nofollow noreferrer">Console error</a></p>
  <p>What I am doing wrong?</p>
  <p>my pom.xml:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
           xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.4.0&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;ru.eco.products.waste&lt;/groupId&gt;
      &lt;artifactId&gt;waste-web&lt;/artifactId&gt;
      &lt;version&gt;0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;name&gt;products-waste-web-client&lt;/name&gt;
      &lt;description&gt;Eco-Waste-Products Project&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;11&lt;/java.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;nz.net.ultraq.thymeleaf&lt;/groupId&gt;
              &lt;artifactId&gt;thymeleaf-layout-dialect&lt;/artifactId&gt;
              &lt;version&gt;2.5.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.thymeleaf.extras&lt;/groupId&gt;
              &lt;artifactId&gt;thymeleaf-extras-springsecurity5&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.guava&lt;/groupId&gt;
              &lt;artifactId&gt;guava&lt;/artifactId&gt;
              &lt;version&gt;29.0-jre&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-integration&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.integration&lt;/groupId&gt;
              &lt;artifactId&gt;spring-integration-http&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-quartz&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-validation&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.session&lt;/groupId&gt;
              &lt;artifactId&gt;spring-session-core&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
  &lt;!--        &lt;dependency&gt;--&gt;
  &lt;!--            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;--&gt;
  &lt;!--            &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;--&gt;
  &lt;!--            &lt;scope&gt;runtime&lt;/scope&gt;--&gt;
  &lt;!--            &lt;optional&gt;true&lt;/optional&gt;--&gt;
  &lt;!--        &lt;/dependency&gt;--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
              &lt;version&gt;42.2.18&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.integration&lt;/groupId&gt;
              &lt;artifactId&gt;spring-integration-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.webjars&lt;/groupId&gt;
              &lt;artifactId&gt;bootstrap&lt;/artifactId&gt;
              &lt;version&gt;4.5.3&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.webjars&lt;/groupId&gt;
              &lt;artifactId&gt;jquery&lt;/artifactId&gt;
              &lt;version&gt;3.5.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-log4j2&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  
  </code></pre>