0

I am moving forward from Struts2 controllers to Spring MVC 2.5

In case of Struts2 OGNL used to take care of populating the property of Action class. Here in Spring MVC 2.5 also they have a SimpleFormController which can call the setCommandClass(UserDefinedBean.class) in the constructor to auto-populate property of the bean class from parameters.

But in case of MultiActionController (this seems very useful for my requirement) I am doing request.getParameter("paramName"); to get parameters from request. Is there any way to utilize the setCommandClass() with MultiActionController?

2
  • Is there any specific reason to use MultiActionController rather than annotated controllers?
    – axtavt
    Apr 24, 2012 at 9:01
  • @axtavt , I'm pretty new with Spring MVC. Googling the words "annotated controllers" found some results. Let me go through the posts and come back to you. I guess(not sure if it is right) "annotated controllers" wont be populating fields automatically unless I define for each and every parameters.
    – tusar
    Apr 24, 2012 at 9:20

1 Answer 1

3

You can have the command object as one of the argument in your action method, eg:

public (ModelAndView | Map | String | void) actionName(HttpServletRequest request, HttpServletResponse response, Object commandObject);

For extensive use of data binding you can always override the initBinder(...) method to have your custom binding and validators.

Between why using Spring 2.5.x ? Why not Spring 3.0.x ? You have more flexibility in the new version by using annotations. Even Spring doesn't recommend using the old method of extending Controllers. Just a suggestion as I am not sure about your design or requirement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.