Spring MVC customized method parameter binding?

I guess the standard Spring MVC way would be to register a custom HttpMessageConverter and use RequestBody instead of RequestParam.

I guess the standard Spring MVC way would be to register a custom HttpMessageConverter and use @RequestBody instead of @RequestParam.

2 +1 for being faster – Ralph Jun 29 at 10:50 This seems a little awkward. By using an HttpMessageConverter I'll have no real access to a HttpServletRequest but only to the binary data that has been sent from the browser to the server. I just want to add a little "magic" ;) – perdian Jun 29 at 11:13.

It is very easy. You can use Converters (that work like one way PropertyEditors but are stateless). See chapter 5.5 Spring 3 Type Conversion in Spring reference.

If such an converter is registered once, you do not need any additional information, you can simply use @RequestMapping(value="/index. Html") public ModelAndView doIndex(@RequestParam Foo param) { For example a simple converter that load an object by its id: @Component @CustomConverter //custom qualifyer public class BUdToUserConverter implements Converter { @Resource private UserDao userDao; @Override public User convert(String source) { Integer id = Integer. Parse(source); return this.userDao.

GetByBusinessId(id); } } A "helper" that registers all Beans with @CustomConverter anntoation public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean { @Resource @CustomConverter private List> customConverter; @Override protected void installFormatters(final FormatterRegistry registry) { super. InstallFormatters(registry); for (Converter converter : customConverter) { registry. AddConverter(converter); } } } How to use it UserController { ... @RequestMapping(value = "/{id}", method = RequestMethod.

GET) public ModelAndView show(@PathVariable("id") User user) { return new ModelAndView("users/show", "user", user); } }.

Thanks, this works nice for converting a single parameter into a user specific object, however I'd like to traverse the complete HttpServletRequest myself and populate the user specific object with values computed depending on the state of the HttpServletRequest. – perdian Jun 29 at 11:15.

Just a quick thank you and the info, that I've found the "correct" solution to the problem. Spring already provides the WebArgumentResolver for this scenario. sergialmar.wordpress.com/2011/03/29/exte... scottfrederick.blogspot.com/2011/03/cust....

You could also use a ModelAttribute to map form beans – Aaron Sheffey Jul 14 at 2:47.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions