| 12 | } |
| 13 | |
| 14 | @Override |
| 15 | public void validate(Object target, Errors errors) { |
| 16 | System.out.println("UserValidator.validate() is called"); |
| 17 | |
| 18 | User user = (User)target; |
| 19 | |
| 20 | String id = user.getId(); |
| 21 | |
| 22 | // if(id==null || "".equals(id.trim())) { |
| 23 | // errors.rejectValue("id", "required"); |
| 24 | // } |
| 25 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "id", "required"); |
| 26 | ValidationUtils.rejectIfEmptyOrWhitespace(errors, "pwd", "required"); |
| 27 | |
| 28 | if(id==null || id.length() < 5 || id.length() > 12) { |
| 29 | errors.rejectValue("id", "invalidLength", new String[]{"5","12"}, null); |
| 30 | } |
| 31 | } |
| 32 | } |