Closed
Description
Dennis Homann opened SPR-10516 and commented
From comments Rossen's comment on #14054 and his comment on #11462, it seems that the following design is intended:
- to allow fine control over query parameters added automatically during a redirect, handlers should accept an argument of type
RedirectAttributes
RedirectAttributes
define a redirect model, which is separate from the default model (part of theModelAndView
returned by the handler). Values in the redirect model are intended as query parameters and will therefore be converted to Strings, values in the default model are intended for rendering and may be "complex" i.e. not string-convertible.- it is recommended to set
RequestMappingHandlerAdapter#ignoreDefaultModelOnRedirect=true
to prevent use of the default model for redirects (if noRedirectAttributes
were used by the handler). This is the default.
Issues:
- Unfortunately, in 3.1.2, the default model is copied into the
ModelAndViewContainer
model inModelAndViewMethodReturnValueHandler:76
, and when the handler usesRedirectAttributes
this will result in merging the default model into the redirect model.- This violate the separation of the two (issue Spring core JMS pom.xml #1) models
- This triggers conversion of all default model values to Strings which may cause conversion exceptions, depending on the available converters (issue Improve annotation processing thread-safety #2).
- The redirect mechanism provided by the framework should play well with other parts of the framework, in particular
ViewResolves
andRedirectViews
or custom redirectingSmartViews
:- When a handler returns a
ModelAndView
with aRedirectView
or aSmartView
object (withisRedirect==true
), it should be presented the redirect model for "rendering" (or default to the default model, if the handler does not useRedirectAttributes
ANDignoreDefaultModelOnRedirect=false
. Right now, it is presented the default model (with values converted to Strings) merged with the redirect model (issues Fixes https://jira.springsource.org/browse/SPR-7721 #3). - When a handler returns a view name, it will be resolved by a
ViewResolver
, which receives a model to make its decision. One could argue what's more useful here: the default model, a potentially existing redirect model, or both. In any case, if there is a default model, the view resolver must have access to the original model values added by the handler. Like the view before, it is presented the default model (with values converted to Strings) merged with the redirect model (issues SPR-7752 - EntityManager proxy now exposes provider specific interface. #4). I have a custom view resolver which is supposed to resolve a view based on a complex model value, which is not possible right now, ifRedirectAttributes
was used by the handler. - If a view resolver returns a
RedirectView
(or redirectingSmartView
), it should again receive the redirect model.
- When a handler returns a
Affects: 3.2.1
2 votes, 4 watchers