Announcement Announcement Module
No announcement yet.
solved getting multiaction controller to work like a formcontroller Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • solved getting multiaction controller to work like a formcontroller

    I've been working on getting request binding and validation working in a multi-action controller without having to use the form controllers. This way I can do all the usual CRUD work in a single class. (I know many of you have conceptual issues with this).

    - No need to change the views, they work exactly like views for form controllers so you can use the <form:form> and <spring:bind> tags with error tags and all that goodness

    - Imagine an Address class with members name,street,city,state,zip

    What we need to do is bind the incoming request to Address and validate it. If there's errors send the user back to the form view, otherwise process the Address object and send the user on to another view.

    public String processAddress(HttpServletRequest request,ModelMap model) {
        // binding
        Object address = new Address();
        ServletRequestDataBinder binder = new ServletRequestDataBinder(address,"address");
        BindException errors = new BindException(binder.getBindingResult());
        // validation
        Validator validator = new AddressValidator(); /* probably should inject this */
        ValidationUtils.invokeValidator(validator, address, errors);
        Map bindMap = errors.getModel();
        if ( errors.hasErrors() ) {
             return "formview";
        } else {
             // do some Address processing here like "ht.saveOrUpdate(address)"
             return "sucessView";
    Last edited by chasd00; Mar 17th, 2009, 02:14 PM. Reason: forum said i can't post links on the first post