Skip to content

ModelAndView is replaced when a RedirectView is used [SPR-14045] #18617

@spring-projects-issues

Description

@spring-projects-issues

Christopher Smith opened SPR-14045 and commented

I have a HandlerInterceptor that is Doing Things for me based on the contents of the model I populate in a controller. I have a controller that returns a ModelAndView with a RedirectView, filling data into the model to be processed by the interceptor before the redirect fires.

However, the ModelAndView object is replaced by Spring between the controller return and the interceptor invocation (the objects have different IDs when inspected). The view is copied, but the model is discarded.

This appears to be a result of interactions between the handler's ignoreDefaultModelOnRedirect and the ModelAndViewContainer; even though a method that returns a ModelAndView is not using the "default" model, the returned model is discarded.

If a controller method returns an explicit model in a ModelAndView, then that model should be retained even when ignoreDefaultModelOnRedirect is set.


Affects: 3.2.16, 4.2.5

Issue Links:

Referenced from: commits 9e3bb1e, 5828648, d7062f6

Backported to: 3.2.17

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions