Announcement Announcement Module
Collapse
No announcement yet.
setMessageCodesResolver using RequestParam annotations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • setMessageCodesResolver using RequestParam annotations

    While attempting to use a custom MessageCodesResolver implementation, I came across a bug when combined with RequestParam annotations.

    Assuming a simple controller...pseudo code I had to remove the 'at' symbol to post it here for some reason.

    Code:
    Controller
    public class MyController
    {
        InitBinder
        public void initBinder(WebDataBinder binder)
        {
             binder.setMessageCodesResolver(new MyCustomCodesResolver());
        }
    
        RequestMapping(value = /foo)
        public String doFoo(RequestParam("id") int id)
        {
            return "somepage";
        }
    }
    If I comment out the binder.setMessageCodesResolver, the doFoo gets called without a problem. As soon as I set a new MessageCodesResolver, even if I set it to the DefaultMessageCodesResolver, the DataBinder returns the following error.

    It appears, that if the messageCodesResolver is already set, it will be fine since it won't actually attempt to create the binding property until needed. By setting it implicitly, it forces it to create the binding property early. This only appears to happen when using RequestParam, since if I remove that from the method, it works as well.

    Code:
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Target bean must not be null
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583)

  • #2
    setMessageCodeResolver with @InitBinder

    Hi there,

    Is there a way to set the MessageCodeResolver in Spring MVC 3.0 as kfroster pointed out there is an eager initialization which results in an error.

    Here is my code snippet

    Code:
    @InitBinder
    protected void initBinder(WebDataBinder binder) {
    		// Override the default message code resolver to a simple message code resolver.  
    		binder.setMessageCodesResolver(new SimpleMessageCodeResolver());
        }

    I think that there should be more documentation on how to customize MessageCodeResolver and how to create your custom message source.

    Regards,

    Mark

    Comment

    Working...
    X