hello dudes. is this possible? i am basically making a Spring CRUD web app using MultiActionController class and would want my forms validated. i have used a SimpleUrlController before and valang works perfectly.
views:
564answers:
1
A:
According to MultiActionControlller API
Consider direct usage of a ServletRequestDataBinder in your controller method, INSTEAD OF relying on a declared command argument. This allows for full control over the entire binder setup and usage, INCLUDING THE INVOCATION OF VALIDATORS and the SUBSEQUENT EVALUATION of binding/validation errors.
So you can use
public class AddMultiActionController extends MultiActionController {
public AddMultiActionController() {
// Set up Valang according to your business requirement
// You can use xml settings instead
setValidators(new Validator [] {new CommandValidator(), new AnotherCommandValidator()});
}
public ModelAndView addCommand(HttpServletRequest request, HttpServletResponse response) throws Exception {
Command command = new Command();
// createBinder is a MultiActionController method
ServletRequestDataBinder binder = createBinder(request, command);
// Sets up any custom editor if necessary
binder.registerCustomEditor(...);
binder.bind(command);
return (!(binder.getErrors().hasErrors())) ? new ModelAndView("success") : new ModelAndView("failure");
}
// similar approach as shown above
public ModelAndView addAnotherCommand(HttpServletRequest request, HttpServletResponse response) throws Exception {
AnotherCommand anotherCommand = new AnotherCommand();
...
}
}
regards,
Arthur Ronald F D Garcia
2009-08-25 02:12:59