added unit test for setRequiredFields with @MVC (SPR-6552)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user