2012-12-06 149 views
0

我們有JSR註解春+ JSR 303驗證組被忽略

 
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; 

} 

一個簡單的bean,我們有一個Spring控制器

 
@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"); 
} 

我們的問題是,當changePassword調用驗證忽略該組(PasswordChange.class)並僅驗證不在該組中的firstName和lastName。

有什麼想法? 非常感謝您的時間。

+0

我看不錯。你有沒有打開調試跟蹤? – Hardy

+0

沒有怪異的消息。因爲它驗證了ChangePassword方法運行和result.hasErrors()爲真全豆。 – nsideras

回答