1
votes

we have a simple bean with JSR annotations

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

@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.

1
Looks good to me. Have you turned on debug trace?Hardy
No weird message. changePassword method runs and result.hasErrors() is true cause it validates the whole bean.nsideras

1 Answers

1
votes

may be some thing with the validation order ? (http://docs.oracle.com/cd/E19798-01/821-1841/gkahp/index.html)-->Customizing Group Validation Order it definitely sound like it!