Blame view

src/main/java/fr/plil/sio/web/mvc/UserValidator.java 743 Bytes
aa193b2b   Julien Iguchi-Cartigny   First version
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  package fr.plil.sio.web.mvc;
  
  import org.springframework.stereotype.Component;
  import org.springframework.validation.Errors;
  import org.springframework.validation.Validator;
  
  @Component
  public class UserValidator implements Validator {
  
      @Override
      public boolean supports(Class<?> clazz) {
          return User.class.equals(clazz);
      }
  
      @Override
      public void validate(Object target, Errors errors) {
          User user = (User)target;
  
          if (user.getUsername().length() < 3) {
              errors.rejectValue("username", "validator.user.username.minimal.size");
          }
  
          if (user.getPassword().length() < 3) {
              errors.rejectValue("password", "validator.user.password.minimal.size");
          }
      }
  
  }