title: form validation not performed, spring boot
body: <p>Perhaps I'm missing something little and stupid. However i have a form with 6 checkboxes, you can check at max 4 of those checkboxes at the same time and this is inside the validate method of the validator. My validator class is the following:</p>
  
  <pre><code>@Component
  public class GraficiUserFormValidator implements Validator {
  
      @Override
      public boolean supports(Class&lt;?&gt; arg0) {
          return arg0.equals(GraficiUserForm.class);
      }
  
      @Override
      public void validate(Object arg0, Errors arg1) {
          GraficiUserForm form = (GraficiUserForm) arg0;
          validateCheckBoxes(arg1, form);
  
      }
  
      private void validateCheckBoxes(Errors arg1, GraficiUserForm form) {
          if ((form.getG1().equals("on") &amp;&amp; form.getG2().equals("on") &amp;&amp; form.getG3().equals("on") &amp;&amp; form.getG4().equals("on") &amp;&amp;
                  form.getG5().equals("on") &amp;&amp; form.getG6().equals("on")) ||(form.getG1().equals("on") &amp;&amp; form.getG2().equals("on") &amp;&amp; form.getG3().equals("on") &amp;&amp; form.getG4().equals("on") &amp;&amp;
                  form.getG5().equals("on"))||(form.getG1().equals("on") &amp;&amp; form.getG2().equals("on") &amp;&amp; form.getG3().equals("on") &amp;&amp; form.getG4().equals("on") &amp;&amp;
                  form.getG6().equals("on"))||(form.getG1().equals("on") &amp;&amp; form.getG2().equals("on") &amp;&amp; form.getG3().equals("on") &amp;&amp; form.getG5().equals("on") &amp;&amp;
                  form.getG6().equals("on"))||(form.getG1().equals("on") &amp;&amp; form.getG2().equals("on") &amp;&amp; form.getG4().equals("on") &amp;&amp; form.getG5().equals("on") &amp;&amp;
                  form.getG6().equals("on"))||(form.getG1().equals("on") &amp;&amp; form.getG3().equals("on") &amp;&amp; form.getG4().equals("on") &amp;&amp; form.getG5().equals("on") &amp;&amp;
                  form.getG6().equals("on"))||(form.getG2().equals("on") &amp;&amp; form.getG3().equals("on") &amp;&amp; form.getG4().equals("on") &amp;&amp; form.getG5().equals("on") &amp;&amp;
                  form.getG6().equals("on"))
                  ){
              arg1.reject("grafici.tooMany", "Troppi grafici selezionati, si possono selezionare solo 4 grafici");
          }
  
      }
  
  }
  </code></pre>
  
  <p>Then i autowired the validator to the Controller:</p>
  
  <pre><code>@Controller
  public class UsersController {
  
      private static final Logger LOGGER = LoggerFactory.getLogger(UsersController.class);
      private final UserService userService;
      private final SitoService sitoService;
      private final ClusterService clusterService;
      private final GraficiUserFormValidator graficiUserFormValidator;
  
      @Autowired
      public UsersController(UserService userService, ClusterService clusterService, SitoService sitoService, GraficiUserFormValidator graficiUserFormValidator) {
          this.userService = userService;
          this.sitoService = sitoService;
          this.clusterService = clusterService;
          this.graficiUserFormValidator = graficiUserFormValidator;
      }
  
      @InitBinder("form")
      public void initBinder(WebDataBinder binder) {
          binder.addValidators(graficiUserFormValidator);
      }
  </code></pre>
  
  <p>and i built up the method for the form to be processed in the same controller:</p>
  
  <pre><code>@PreAuthorize("hasAuthority('ADMIN') or hasAuthority('CLUSTERADMIN') or hasAuthority('SITEADMIN')")
      @RequestMapping(value = "/update/settings", method = RequestMethod.POST)
      public String updateSettingsGraphs(@Valid GraficiUserForm form, HttpSession session, HttpServletRequest request, BindingResult result, 
              Model model, Long id){
          SecurityContextHolderAwareRequestWrapper wrapper = new SecurityContextHolderAwareRequestWrapper(request, null);
  
          if (result.hasErrors()) {
              if (wrapper.isUserInRole("ADMIN")) {
                  result.reject("graphs.tooMany", "Puoi selezionare solo quattro grafici alla volta");
                  Collection&lt;User&gt; users = userService.getAllUsers();
                  model.addAttribute("users", users);
  
  
                  for (User user : users) {
                      model.addAttribute("form"+user.getId().toString(), new GraficiUserForm());
                  }
  
                  return "users";
              }
  
              else if (wrapper.isUserInRole("CLUSTERADMIN")) {
                  result.reject("graphs.tooMany", "Puoi selezionare solo quattro grafici alla volta");
                  Collection&lt;User&gt; users = clusterService.getAllByCluster(id);
                  model.addAttribute("users", users);
  
  
                  for (User user : users) {
                      model.addAttribute("form"+user.getId().toString(), new GraficiUserForm());
                  }
                  return "users-cluster";
              }
  
              else {
                  result.reject("graphs.tooMany", "Puoi selezionare solo quattro grafici alla volta");
                  Collection&lt;User&gt; users = sitoService.getAllBySite(id);
                  model.addAttribute("users", users);
  
  
                  for (User user : users) {
                      model.addAttribute("form"+user.getId().toString(), new GraficiUserForm());
                  }
                  return "users-site";
              }
          }
          User user = userService.getUserById(form.getUserid());
          if("on".equals(form.getG1())){
              user.setG1("S");
          } else {
              user.setG1("N");
          }
          if("on".equals(form.getG2())){
              user.setG2("S");
          } else {
              user.setG2("N");
          }
          if("on".equals(form.getG3())){
              user.setG3("S");
          } else {
              user.setG3("N");
          }
          if("on".equals(form.getG4())){
              user.setG4("S");
          } else {
              user.setG4("N");
          }
          if("on".equals(form.getG5())){
              user.setG5("S");
          } else {
              user.setG5("N");
          }
          if("on".equals(form.getG6())){
              user.setG6("S");
          } else {
              user.setG6("N");
          }
          user = userService.save(user);
          if (wrapper.isUserInRole("ADMIN")) {
              return "redirect:/users";
          }
  
          else if (wrapper.isUserInRole("CLUSTERADMIN")) {
              return "redirect:/users-cluster";
          }
  
          else {
              return "redirect:/users-site";
          }
  
      }
  
  }
  </code></pre>
  
  <p>My webpage is built by freemarker and is as follows:</p>
  
  <pre><code>&lt;#-- @ftlvariable name="users" type="java.util.List&lt;it.energyway.application.domain.User&gt;" --&gt;
  &lt;#-- @ftlvariable name="_csrf" type="org.springframework.security.web.csrf.CsrfToken" --&gt;
  &lt;#list users as user&gt;
  &lt;#-- @ftlvariable name="form${user.id}" type="it.energyway.application.domain.GraficiUserForm" --&gt;
  &lt;/#list&gt;
  &lt;#import "/spring.ftl" as spring&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html lang="it"&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;title&gt;List of Users&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;nav role="navigation"&gt;
      &lt;ul&gt;
          &lt;li&gt;&lt;a href="/"&gt;Dashboard&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="/user/create"&gt;Create a new user&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;Amministrazione
              &lt;ul&gt;
                  &lt;li&gt;&lt;a href="/users"&gt;Gestione  Utenti e Permessi&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
      &lt;/ul&gt;
  &lt;/nav&gt;
  
  &lt;h1&gt;Utenti&lt;/h1&gt;
  
  &lt;table&gt;
      &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;E-mail&lt;/th&gt;
          &lt;th&gt;Role&lt;/th&gt;
          &lt;th&gt;Grafico 1&lt;/th&gt;
          &lt;th&gt;Grafico 2&lt;/th&gt;
          &lt;th&gt;Grafico 3&lt;/th&gt;
          &lt;th&gt;Grafico 4&lt;/th&gt;
          &lt;th&gt;Grafico 5&lt;/th&gt;
          &lt;th&gt;Grafico 6&lt;/th&gt;
          &lt;th&gt;Cambio&lt;/th&gt;
      &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
      &lt;#list users as user&gt;
      &lt;form role="form${user.id}" name="form${user.id}" action="/update/settings" method="post"&gt;
      &lt;input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/&gt;
      &lt;input type="hidden" name="userid" id="userid" value="${user.id}"/&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;a href="/user/${user.id}"&gt;${user.email}&lt;/a&gt;&lt;/td&gt;
          &lt;td&gt;${user.role}&lt;/td&gt;
          &lt;td&gt;&lt;input class="graphs" type="checkbox" name="g1" &lt;#if (user.g1 == "S")&gt;checked=true&lt;#else&gt;&lt;/#if&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input class="graphs" type="checkbox" name="g2" &lt;#if (user.g2 == "S")&gt;checked=true&lt;#else&gt;&lt;/#if&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input class="graphs" type="checkbox" name="g3" &lt;#if (user.g3 == "S")&gt;checked=true&lt;#else&gt;&lt;/#if&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input class="graphs" type="checkbox" name="g4" &lt;#if (user.g4 == "S")&gt;checked=true&lt;#else&gt;&lt;/#if&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input class="graphs" type="checkbox" name="g5" &lt;#if (user.g5 == "S")&gt;checked=true&lt;#else&gt;&lt;/#if&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input class="graphs" type="checkbox" name="g6" &lt;#if (user.g6 == "S")&gt;checked=true&lt;#else&gt;&lt;/#if&gt;&lt;/td&gt;
          &lt;td&gt;&lt;button type="submit"&gt;Save&lt;/button&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/form&gt;
      &lt;/#list&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;#list users as user&gt;
      &lt;@spring.bind "form${user.id}" /&gt;
  &lt;/#list&gt;
  &lt;#if (spring.status.error)??&gt;
  &lt;ul&gt;
      &lt;#list spring.status.errorMessages as error&gt;
          &lt;li&gt;${error}&lt;/li&gt;
      &lt;/#list&gt;
  &lt;/ul&gt;&lt;#else&gt;
  &lt;/#if&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When i select more than 4 checkboxes it doesn't throw any error in the output...
  Anyone has any idea of why?</p>