added unit test for setRequiredFields with @MVC (SPR-6552)

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2659 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller
2009-12-14 21:32:26 +00:00
parent 18ec90aff9
commit 4e278ffad0
@@ -1575,6 +1575,7 @@ public class ServletAnnotationControllerTests {
@InitBinder
private void initBinder(WebDataBinder binder) {
binder.initBeanPropertyAccess();
binder.setRequiredFields("sex");
LocalValidatorFactoryBean vf = new LocalValidatorFactoryBean();
vf.afterPropertiesSet();
binder.setValidator(vf);
@@ -1582,6 +1583,15 @@ public class ServletAnnotationControllerTests {
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
@Override
@RequestMapping("/myPath.do")
public String myHandle(@ModelAttribute("myCommand") @Valid TestBean tb, BindingResult errors, ModelMap model) {
if (!errors.hasFieldErrors("sex")) {
throw new IllegalStateException("requiredFields not applied");
}
return super.myHandle(tb, errors, model);
}
}
@Controller