我將Struts 1.3項目轉換爲Spring。而不是struts表單域,我使用的是spring表單。在DAO驗證後,Spring-MVC表單驗證突出顯示輸入字段
我在struts中使用ActionErrors來使用errorStyleClass屬性突出顯示該字段。
同樣,在春季cssErrorClass可用。但是,如何在dao驗證後使用它?
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@ModelAttribute("login") @Validated Login login, BindingResult result, Model model) {
if (result.hasErrors()) {
//THIS VALIDATION DONE BY ANNOTATION AND HIGHLIGHTING THE FIELD
//USING "cssErrorClass"
return HOMEPAGE;
}
boolean checkAuthentication = authService.checkAuthentication(login);
if(!checkAuthentication){
// HOW TO SET THE ERROR HERE?
// Is there any way to set the error like
// error.setMessage("userId","invalid.data");
// so that, is it possible to display error message by
// highlighting the fields using "cssErrorClass"?
}
return HOMEPAGE;
}
你看這個問題:HTTP ://stackoverflow.com/questions/4013378/spring-mvc-and-jsr-303-hibernate-conditional-validation RQ = 1? –
是的。我見過這個例子。但是,它表示,沒有定義驗證方法。如果要創建驗證方法,那裏面的實現應該是什麼? – Shakthi