-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Controlling flashmap from a ModelAndView #28069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm not sure what you're proposing from an API perspective, but adding flash attributes directly to a |
In the case where the creation of the ModelAndView is delegated away from the controller, and is created based on tests in this delegate, ModelAndView is a perfect return value from this delegate. RedirectAttributesModelMap is not different opinionated as the ModelMap in ModelAndView. Attributes stored in Model are also passed to a redirect, so why not RedirectAttributesModelMap attributes. What you seem to indicate is that you want Model and FlashMap 'contained' in the Controller, and block designs where ModelAndView (with flashmap attributes) are created in a controller delegate. And this 'blockade' is exactly how it is currently implemented. The ModelMap (name,value pairs) contained in ModelAndView is not accessible and one can only add normal attributes to it. ModelAndView allows for a redirect view, but without the needed RedirectAttributesModelMap.flashAttributes. I seek to change this, so one can create a redirect ModelAndView away from the controller, with the needed RedirectAttributesModelMap.flashAttributes. I see no reason to allow ModalAndView attributes to be set, and to deny this to flash-attributes. |
There is no intent to block anything to be honest, only some decisions from a number of years ago. Trying to recollect, so previously there was confusion with attributes from the "default" model ending up in redirect URLs (see #11462 and many related issues, both before and follow-ups). A specific goal was to clearly separate redirects from rendering, and encourage never using from the "default" model on redirect which is also a security concern. The reason this relates to flash attributes is they both apply to redirects and need to be exposed in the same places. Here you're returning In any case, it's been like this for a long time and not revisited much or discussed so I'm not keen to revisit the current arrangement in I am also wondering if you've considered an approach with passing |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
this was not a request for support. a kludge like the one suggested was already implemented. As to opinionated opinions, it was a suggestion for a much needed improvement of a incomplete and wrong api. |
Thanks for the feedback. I've created #28324 to revisit this area in more detail for 6.0. |
Uh oh!
There was an error while loading. Please reload this page.
Currently (Spring Boot2.6.2) it is not possible to add flashmap attributes to a
ModelAndView
.In the
ModelAndView
constructor, the flash attributes from aRedirectAttributesModelMap
are not merged into the regularModelMap
contained inModelAndView
.The test in
RequestMappingHandlerAdapter.getModelAndView
forRedirectAttributes
fails, because theModelAndView
reads the attributes from theRedirectAttributesModelMap
and merges them into the already existingModelMap
inModelAndView
.The only way now to cause the
ModelMap
to be an instance ofRedirectAttributes
is by adding aRedirectAttributes
to theController
method.What was expected is that the
RedirectAttributesModelMap
was passed to theModelAndViewContainer
so it could be picked up by the test inRequestMappingHandlerAdapter.getModelAndView()
.If a
RedirectAttributesModelMap
could turn up inRequestMappingHandlerAdapter.getModelAndView
it would be a beautiful way to create aView
factory returning aModelAndView
(with flash attributes) without having to signal this in theController
method. And providing a clean separation.A workaround currently is to fetch the flashmap via
RequestContextUtils
, but that looks like a kludge.The text was updated successfully, but these errors were encountered: