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

Webflux support for flash attributes [SPR-16026] #20575

Open
spring-projects-issues opened this issue Sep 29, 2017 · 7 comments
Open

Webflux support for flash attributes [SPR-16026] #20575

spring-projects-issues opened this issue Sep 29, 2017 · 7 comments
Labels
in: web type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 29, 2017

Adrien Sanchez opened SPR-16026 and commented

Hello,

I faced an issue when wanting to perform a redirection with redirect attributes on a Spring Webflux application.

In Spring MVC, I used to add the RedirectAttributes parameter in my controller methods to configure the attributes/flash attributes that I wanted to transmit through my redirection.

However, in Spring Webflux, there seems to be no equivalent to the Spring MVC RedirectAttributes class. This is a problem as Spring Webflux controllers should be able to perform redirections with attributes too.

I tried using the redirectTo method of the reactive Rendering API, that works to perform a redirection, but there's no way to transmit parameters here too. Maybe this API could evolve to include this possibility ? And do you have any workaround that could be used at the moment?

Thanks and regards,
Adrien


Affects: 5.0 RC3, 5.0 RC4, 5.0 GA

Reference URL: https://stackoverflow.com/questions/46474452/redirectattributes-not-working-with-spring-5

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 29, 2017

Rossen Stoyanchev commented

No support for flash attributes currently in WebFlux.

You can add query params to the redirect URL /foo?q=1" and use URI vars to refer to model attributes (and URI vars from the current URL) "/foo?q={value}". WebFlux does not automatically append model attributes to the query and that reduces the need for something more explicit like RedirectAttributes.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 29, 2017

Adrien Sanchez commented

Hi Rossen, thanks for your answer.

If I understand correctly, we must go through query params to pass attributes in a redirection with Webflux? So after the redirection, those attributes will be visible in the browser URL, and we also need to map them explicitly in the code of the targeted controller to use them?

What I liked about RedirectAttributes was the fact that they were directly binded to the model in the targeted controller to be used, for instance, in a template (Thymeleaf in my case).

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 2, 2017

Rossen Stoyanchev commented

Is it primarily about those attributes being in the model after the redirect? In other words are they mostly simple type attributes that can be appended to the query? In that case you could try a @ModelAttribute method to add query params to the model after a redirect using @RequestParam to access them. You can also inject all query params into the model attriute method with @RequestParam MultiValueMap<String,String> params. Also such a method can be shared with an @ControllerAdvice across all or a subset of controllers.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 2, 2017

Rossen Stoyanchev commented

In any case I am turning this into a feature request to support flash attributes.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 3, 2017

Adrien Sanchez commented

Thanks for your help, I'll try those workarounds. But yes, this feature would be very appreciated to perform redirections with model attributes easily.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Apr 12, 2018

cafebaby commented

If you want to redirect the value passed, you can annotate @SessionAttributes({ "path", "user" }) on the class and use the Model model to store the value. Use @SessionAttribute("user") User user or Receive with Model in the receiving method

@spring-projects-issues spring-projects-issues added type: enhancement in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.x Backlog milestone Jan 11, 2019
@shiveenp
Copy link

@shiveenp shiveenp commented Jan 31, 2019

I have run into the same issue when trying to persist a user session info through redirects. Currently working around by storing the data in state as a nonce:{data} but would like to see this built in Webflux so we can do it properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants