-
Notifications
You must be signed in to change notification settings - Fork 48
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
Handle flash attributes on htmx redirects #137
base: main
Are you sure you want to change the base?
Conversation
@wimdeblauwe there is a limitation, because the flash attribute processing does not work if |
aac224b
to
8097ea9
Compare
8097ea9
to
a15d7c2
Compare
BTW @wimdeblauwe there is more magic done by RedirectView
We could support all of them to behave as similarly as possible to Spring. Let me know what you think about it. |
I couldn't find an alternative approach that was compatible with using JTE Models as the return. I'm happy to try another approach if you have any suggestions. |
@checketts let's move the discussion about an alternative approach to the initial issue #127. |
} | ||
} | ||
|
||
private void buildAndRender(HtmxResponse htmxResponse, ModelAndView mav, HttpServletRequest request, HttpServletResponse response) { | ||
View v = htmxResponseHandlerMethodReturnValueHandler.toView(htmxResponse); | ||
try { | ||
v.render(mav.getModel(), request, response); | ||
htmxResponseHandlerMethodReturnValueHandler.addHxHeaders(htmxResponse, response); | ||
// ModelAndViewContainer is not available here, so flash attributes won't work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure when exactly the flash attributes will not work? Maybe we should document this in the README?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I pointed out in my comment above.
If you are willing to implement that, it would be great if we align as much as possible with |
Sure, but let's merge this before and I'll create a separate PR for it. Okay? |
ok, but can we already merge this? Don't we need a solution to #127 first? |
I'm not sure because I need more information from @checketts on how he uses it in his projects. But if you ask me, we should revert #127 in favor of a better solution to his issue. It's definitely the wrong approach to render views in HtmxHandlerInterceptor#postHandle which was introduced by #127. And as far as I know, using See https://jte.gg/spring-boot-starter-3/ or https://github.com/casid/jte/tree/main/jte-spring-boot-starter-3/src/main/java/gg/jte/springframework/boot/autoconfigure for more information about integration with Spring Boot. |
This adds handling for flash attributes via
RedirectAttributes
. Now you can perform client-side redirects with htmx and the flash attributes work as with normal redirects.Fixes #96