Announcement Announcement Module
No announcement yet.
WebArgumentResolver and binding Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • WebArgumentResolver and binding

    I'm new to Spring, formerly doing most of my work with various Struts based frameworks. I'm using Spring 2.5.6 and have run into the following situation.

    My controllers need to have access to an object living in the HttpSession. The name of the session attribute is partially determined by a combination of request parameters and object type.

    Assuming my controller looks like this:
    	@RequestMapping(method = RequestMethod.GET)
    	public ModelAndView update(WebRequest req, SomeClass test)
    My thinking was I could provide AnnotationMethodHandlerAdapter with a custom WebArgumentResolver that would get be able to get the correct object out of the session and return it. Now, that piece of it works fine. The WebArgumentResolver does what I expect.

    My problem is that I want to bind request parameters to the object. For example, with the above controller and NO argument resolver, the "test" object would be instantiated and the properties set with the parameters.

    But, with the argument resolver in place, parameters aren't bound to the object returned by the resolver.

    Is there another way to achieve what I'm looking for? I'm not really looking to resolve the objects in each controller. My goal with what I was trying is to solve the issue at a high enough level that the controller doesn't need to worry about it. My inexperience with Spring may be to blame if I'm missing an obvious solution or best practice.