Hello,
I've created an entity (AppUser) and proper controller/views via controller scaffold.
The entity has a field with @Size(min = 4, max = 20) validation constraint.
With the automatic controller I'm not able to perform create operation when the field has invalid size. Fine.
Then I wanted to do some customizations:
I've created a manual controller:
I've copied views/appuser/create.jspx to views/appuser_my/create.jspx.Code:controller class --class ~.controller.MyUserController --preferredMapping /appuser_my
The manual controller has the following code:
It turns that if I submit an invalid field value to my manual controller, the validation does not take place, and I'm able to perform the post operation with invalid values.Code:@RequestMapping("/appuser_my/**") @Controller public class MyUserController { @RequestMapping(method = RequestMethod.POST) public String post(@Valid AppUser appUser, BindingResult result, ModelMap modelMap) { System.out.println("post " + this.getClass().getName()); System.out.println(appUser.toString()); return "redirect:/appuser"; } @RequestMapping(value = "/appuser_my/form", method = RequestMethod.GET) public String createForm(ModelMap modelMap) { System.out.println("createForm"); modelMap.addAttribute("appUser", new AppUser()); return "appuser_my/create"; } }
I have also noticed that if I remove the BindingResult arg from my post method a validation happens and I receive an internal error screen:
org.springframework.validation.BeanPropertyBinding Result: 1 errors Field error in object 'appUser' on field 'password': rejected value [b]; codes [Size.appUser.password,Size.password,Size.java.lang .String,Size]; arguments [org.springframework.context.support.DefaultMessage SourceResolvable: codes [appUser.password,password]; arguments []; default message [password],{javax.validation.constraints.Size.message},4,[Ljava.lang.Class;@c9537b,20,[Ljava.lang.Class;@187d27e]; default message [size must be between 4 and 20]
I'm using Roo 1.0.0
Why can't I produce validation behavior with my manual controller ?
Regards,
Renato


Reply With Quote
In my opinion, it pays off the cost of conditional redirect implementation.
.
