0

I'm using a spring 3 RequestMapping within a controller defined like so :

@RequestMapping(value = "/myServlet" , method = RequestMethod.GET)
      public @ResponseBody String performAction() {
        return "success";
      }

I'm attempting to implement a method which uses the Spring 2 method parameters, SimpleFormController is being extended, onSubmitAction is being overidden and a method using the onSubmitAction parameters is being called :

    protected void onSubmitAction(ActionRequest request,
                                  ActionResponse response,
                                  Object command,
                                  BindException errors)
{
methodCall(request,response,command,errors);
}

Is it possible to access these parameters(request,response,command,errors) using the spring 3 annotation @RequestMapping, or do I need to implement my controller differently?

blue-sky
  • 51,962
  • 152
  • 427
  • 752

1 Answers1

0

Spring MVC is incredibly intelligent about binding request data to controller method parameters.

Here's an example from some of my own code that may, by illustration, answer your question:

@RequestMapping(value = "/my-account/email", method = RequestMethod.PUT)
public ModelAndView updateEmail(EditEmailForm editEmailForm, BindingResult result) {
    // ...
}

Here, Spring MVC intelligently binds request parameters to my "command" object (editEmailForm) and binding/validation results to result. Errors are accessible through result, e.g. result.hasErrors(), result.getErrors(), etc.

There's a whole lot of "magic" that goes on behind the scenes, obviously, but Spring MVC will just about always give you exactly what you need if you just "ask" for it in the method signature.

Hope that helps.

Kent Rancourt
  • 1,555
  • 1
  • 11
  • 19