Announcement Announcement Module
Collapse
No announcement yet.
Spring + JSR 303 Validation group is ignored Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring + JSR 303 Validation group is ignored

    Hello,

    we have a simple bean with JSR annotations

    Code:
    public class CustomerDTO {
    
        private static final long serialVersionUID = 1L;
    
        private Integer id;
    
        @NotEmpty(message = "{customer.firstname.empty}")
        private String firstName;
    
        @NotEmpty(message = "{customer.lastname.empty}")
        private String lastName;
    
        @NotEmpty(groups={PasswordChange.class}, message="{password.empty}")
        private String password;
    
        @NotEmpty(groups={PasswordChange.class}, message="{confirmation.password.empty}")
        private String password2;
    
    }

    and we have a Spring Controller


    Code:
    @RequestMapping(value="/changePassword", method = RequestMethod.POST)
    public String changePassword(@Validated({ PasswordChange.class }) @ModelAttribute("customerdto") CustomerDTO customerDTO, BindingResult result, Locale locale) {
        logger.debug("Change Password was submitted with information: " + customerDTO.toString());
        try {
            passwordStrengthPolicy.checkPasswordStrength(locale, customerDTO.getPassword());
            if (result.hasErrors()) {
                return "changePassword";
            }
            logger.debug("Calling customer service changePassword: " + customerDTO);
            customerOnlineNewService.changePassword(customerDTO);
        } catch (PasswordNotChangedException e) {
            logger.error("Could not change password PasswordNotChangedException: " + customerDTO.toString());
                return "changePassword";
        } catch (PasswordNotSecureException e) {
            return "changePassword";
        }
        return createRedirectViewPath("changePassword");
    }
    Our problem is that when changePassword is invoked the validator ignores the group(PasswordChange.class) and validates only firstName and lastName which are not in the group.

    Any idea?
    Thank you very much for your time.
Working...
X