Browse Source

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
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
4e278ffad0
  1. 10
      org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java

10
org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/mvc/annotation/ServletAnnotationControllerTests.java

@ -1575,6 +1575,7 @@ public class ServletAnnotationControllerTests { @@ -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 { @@ -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

Loading…
Cancel
Save