Skip to content

Default model values are always copied into the redirect model when RedirectAttributes are used [SPR-10516] #15147

Closed
@spring-projects-issues

Description

@spring-projects-issues

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 the ModelAndView 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 no RedirectAttributes were used by the handler). This is the default.

Issues:

  • Unfortunately, in 3.1.2, the default model is copied into the ModelAndViewContainer model in ModelAndViewMethodReturnValueHandler:76, and when the handler uses RedirectAttributes this will result in merging the default model into the redirect model.
  • The redirect mechanism provided by the framework should play well with other parts of the framework, in particular ViewResolves and RedirectViews or custom redirecting SmartViews:
    • When a handler returns a ModelAndView with a RedirectView or a SmartView object (with isRedirect==true), it should be presented the redirect model for "rendering" (or default to the default model, if the handler does not use RedirectAttributes AND ignoreDefaultModelOnRedirect=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, if RedirectAttributes was used by the handler.
    • If a view resolver returns a RedirectView (or redirecting SmartView), it should again receive the redirect model.

Affects: 3.2.1

2 votes, 4 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: bulk-closedAn outdated, unresolved issue that's closed in bulk as part of a cleaning process

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions