Skip to content
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

Provide precise control over the attributes used in a redirect scenario [SPR-6796] #11462

Closed
spring-projects-issues opened this issue Feb 3, 2010 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 3, 2010

Jon Harper opened SPR-6796 and commented

There needs to be a way to issue a redirect using the String type and to specify that there should be no exposing of the model to the view.

One use case:
HandlerInterceptors are commonly used to add data to the model. If the controller supports POST request and does a redirect (which is the most common case) then the data added by the handler interceptor gets appended to the redirect url. This is undesirable. See http://forum.springsource.org/showthread.php?t=84140.

Another use case:
The controller uses a session attribute. The GET inserts into the model (session). The POST accepts a SessionStatus and calls status.setComplete() and then does a redirect using "redirect:view". The model data is still appended to the end of the redirected URL. The programmer now has to accept the ModelMap and call clear() on it. This should really not be required. See http://forum.springsource.org/showthread.php?p=275392.

Therefore there needs to be a very simple way (i.e. view String prefix ) to do a redirect without exposing the model to the view. I see this as the default use case and the case of exposing the model as a less common use case.

Jon


Affects: 3.0 GA

Reference URL: http://forum.springsource.org/showthread.php?t=84140

Issue Links:

3 votes, 4 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Sep 16, 2011

Rossen Stoyanchev commented

We've addressed the concern for precise control over redirect attributes through a number of changes.

RedirectAttributes controller method argument

@RequestMapping methods can declare a RedirectAttributes arg and use it to add the exact attributes for a redirect. If the controller does redirect, the content of RedirectAttributes is used. If the controller doesn't redirect the "default" model is used.

Furthermore, in RequestMappingHandlerAdapter you can set ignoreDefaultModelOnRedirect=true to avoid use of the "default" model when any controller redirects. A controller then either has to use RedirectAttributes or not doing so means no attributes.

URI variable placeholders

A redirect URL can now contain URI variable placeholders. Any attributes used up to expand the placeholders are not appended as query params. Although this doesn't address the issue on its own, it helps and also could be combined with the exposeModelAttributes flag in RedirectView (see next section).

UriComponentsBuilder

The UriComponentsBuilder (#10641) now available provides an convenient way to prepare the redirect string in a chained method style including query param, encoding, etc. If this is your preferred approach, the 'exposeModelAttributes' flag in RedirectView can be used to turn off appending of query params entirely. It can be done globally by creating a simple subclass of UrlBasedViewResolver to always creates RedirectView with exposeModelAttributes set to false.

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

Modified subject from "Introduce redirect prefix that doesn't expose model (needed for redirect after post)" to "Provide precise control over the attributes used in a redirect scenario" as the original description is bit more open to different approaches and also to reflect more accurately the actual changes included in the release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants