Announcement Announcement Module
Collapse
No announcement yet.
@ModelAttribute ModelMap works diferent in 2.5.1 and 2.5.2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ModelAttribute ModelMap works diferent in 2.5.1 and 2.5.2

    Hello,

    I have the following code in a controller:

    Code:
            @RequestMapping
    	public void list(@ModelAttribute ModelMap model,
    			@ModelAttribute SearchBean searchBean) {
    		
                    ...
                    //use the model arround here
                    ...
    	}
    In 2.5.1 the model argument (@ModelAttribute ModelMap model) was the model map of the request.

    In 2.5.2 the model argument (@ModelAttribute ModelMap model) is treated like an attribute called modelMap inside the model map of the request

    To have the same behavior than the one in 2.5.1 I just need to remove the @ModelAttribute from the ModelMap, something like this:

    Code:
            @RequestMapping
    	public void list(ModelMap model,
    			@ModelAttribute SearchBean searchBean) {
    		
                    ...
                    //use the model arround here
                    ...
    	}
    but... Does anyone knows why was this change made? was that a 2.5.1 bug fixed in 2.5.2?

  • #2
    Hi spulido99,

    Although I have not checked the Spring Jira to confirm if this was a bug fixed in 2.5.2, the way @ModelAttribute is implemented in 2.5.2 is correct.

    If you have a look at the api docs for @ModelAttribute, you will see that it is meant for binding to the request. Also, have a look at @RequestMapping, you will notice that ModelMap is autowired into the handler method for use, thus @ModelAttribute will give you an entirely different expected behavior.

    Josh

    Comment


    • #3
      I agree with Josh - the way it is working now seems correct. The specially-handled data types like ModelMap don't need to be annotated with anything when they are request handler method parameters.

      Comment

      Working...
      X