Replies: 1 comment 2 replies
-
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To integrate HTMX better with Spring ViewComponent, I propose the @ViewAction annotation that will generate an HTTP Endpoint when we add it to a method inside our ViewComponent.
We then can annotate any div with the
view:action
attribute that will create HTMX attributes to call the method from the browser. As we just translate the attribute to htmx attributes we can use additional htmx attributes to customize the behaviour.As the translation happen after the view rendering it is template language independent.
This will be rendered to the following HTML:
It should also be possible to customize the @ViewAction Annotation with the path and requestmethod that will be used for the htmx attributes like this:
I already got a working version on the dev branch you can test out yourself:
https://github.com/tschuehly/spring-view-component/blob/dev/thymeleaf/src/test/kotlin/de/tschuehly/spring/viewcomponent/thymeleaf/application/web/action/ActionViewComponent.kt
This is the filter that is responsible for translating the view:action attribute to hx-attributes:
https://github.com/tschuehly/spring-view-component/blob/dev/core/src/main/kotlin/de/tschuehly/spring/viewcomponent/core/ViewActionFilter.kt
This is the controller, the mapping currently maps to everything with 2 slashes so I need to figure the correct configuration out:
https://github.com/tschuehly/spring-view-component/blob/dev/core/src/main/kotlin/de/tschuehly/spring/viewcomponent/core/ViewActionController.kt
Beta Was this translation helpful? Give feedback.
All reactions