-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Oliver Drotbohm opened SPR-12542 and commented
I have a controller annotated with @SessionAttributes("cart") and q request handling method like this:
@RequestMapping(value = "/cart", method = RequestMethod.POST)
public String addToCart(@RequestParam("product") Long productId, @ModelAttribute Cart cart) {
…
return "redirect:…";
}If the call to that controller method is the very first one made to that controller in the session, the Cart object is created by an @ModelAttribute annotated method and handed to the method execution. The cart is then not added to the session attributes if ignoreDefaultModelOnRedirect=true as ModelFactory.updateModel(…) looks up the Model from the ModelAndViewContainer which returns the redirect model for a redirect view.
Once you issue a request to a controller method not returning a redirect view, the cart is added to the session and looked up from it for the invocation of the method above. Thus subsequent modifications of the object transparently end up in the session.
We should make sure the default model is used to populate the session attributes independently from the view type that is returned.
Affects: 4.0.8, 4.1.3
Issue Links:
- ModelAndView is replaced when a RedirectView is used [SPR-14045] #18617 ModelAndView is replaced when a RedirectView is used
Referenced from: commits ea05e0b