In multiple projects I've implemented custom ViewResolvers that issue redirects based on view names. Similar to how redirect: and forward: works. They've interpreted these view names and built the redirects based on context and various factors such as locale of the logged in user. For instance "my-project:checkout-page" or "project:2156".
However flash attributes don't work for the redirects these ViewResolvers issue.
The reason is that the ModelAndViewContainer needs to have redirectModelScenario set in order for them to work. The only place I've found where I can set it is in a HandlerMethodReturnValueHandler. Unfortunately the ViewNameMethodReturnValueHandler eats all returned Strings so I have to extend it and replace the default one with my own. The same goes for ModelAndViewMethodReturnValueHandler. Replacing any of them means explicitly configuring all of the default ones since the custom ones that I could add to RequestMappingHandlerAdapter are executed after the default ones and so can't operate on String or ModelAndViewContainer.
I've come up with a solution but it's not very elegant so I'm wondering if you know of a better solution. Ideally ViewResolvers should be able to output redirects with flash attributes.
My solution extends RequestMappingHandlerAdapter and detects whether the returned view name is in a format that will be processed by a custom ViewResolver later. I'm not happy with how the logic for this gets duplicated.
Attached is maven projects with two DispatcherServlets that illustrate the problem, one where it works and one where it doesn't. It's runnable from command line with mvn jetty:run.
Here's my custom RequestMappingHandlerAdapter: