-
Notifications
You must be signed in to change notification settings - Fork 49
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
Functional HTMX Endpoints #104
Comments
@checketts @xhaggi What are your thoughts on this? |
1 - Reflection (Against)I would avoid the reflection scanning (or at least ensure you have a graalvm compatible solution). The existing SpringBoot functional routing doesn't use an annotation scan, does it? 2 - Standard method/path representation (For)I do like how the path and method are representated in the endpoint, so it can be used consistently 3 - Adding endpoint to model (Yuck)I don't like how the endpoint has to be added to the model to facilitate referencing it. Since it adds boiler plate code to set it and non-typesafe ways of calling it. What if instead the endpoint was a property on a bean that then is reference via the bean So I think the idea has merit, but I would like to see the utility played with further. |
There are 2 problem with the bean method
In an optimal scenario I would like to reference them statically like I do it with URLs now, instead of passing it into the model. Maybe there is a way to do it statically: https://stackoverflow.com/questions/12537851/accessing-spring-beans-in-static-method The non typesafe access is more of a Spring MVC problem: https://github.com/tschuehly/htmx-spring-workshop/blob/endpoint-test/src/main/java/de/tschuehly/easy/spring/auth/htmx/HtmxComponent.java |
I don't see either points you brought up as problems though. Perhaps I'm misunderstanding something Point 1- You are saying the a bean wouldn't be needed and can could be referenced as a static reference. I'm not familiar with that syntax. Do you have an example of it? Is it simpler than the bean approach? However, I'm also looking more and more at JTE. So I'm very interested in that type safe templating and considering how the HTMX helpers could be helpful in those cases. In the next few weeks I plan on porting a Thymeleaf HTMX app over to JTE to learn more and compare. |
Would love to hear how that went afterwards. I was also thinking about porting my Taming Thymeleaf application to JTE to compare (The speed and the GraalVM compatibility are really nice I think). |
Using JTE you would pass in the Bean into the Model. -> Here the Model is the ViewContext
I like to look at both but as I've said above it is pretty easy For registering I looked at how Spring does it and I think I will use a BeanDefinitionParser: I would try to implement these two in my test project, and if you guys are fine with it then I could start working on a PR |
I have seen the first post without any context on X during the weekend and was wondering what the |
Sadly the Bean Definition Parser is just for XML. Looks like there is no way around reflection. |
I got a first working version here: The AbstractHtmxEndpoint would be the base implementation, that then could be implemented for ModelAndView and for Spring ViewComponent with ViewContext. I also made the Endpoint scanning configurable. What do you guys think? |
Concept of views is great, I would love to work with them like this. |
I don't think I understand the example. Isn't it just doing this (i.e. marshalling a POST request and rendering a view)? @Controller
public class ExampleController {
@PostMapping("/createUser")
public String createUser(UserForm user) {
return "createUser";
}
} I know it's just an example, but it seems odd to do the whole "endpoint" thing when a |
@dsyer
But the information that it needs an hx-get needs to be encoded in the URL. The HX-Target attribute is another candidate for adding to the HtmxEndpoint. Imagine you want to open this EditUserModal from another part of the application.
All information is embedded in the HtmxEndpoint. If we now want to show the modal in a different container instead of the modal we can change it in the endpoint and it would change everywhere.
Hope this makes it clear 🙂 |
@tschuehly and me had a discussion about this issue and this is a summary of that. To get this idea included in the library, I would like to following to happen:
For the Thymeleaf part, we can expand the
With the controller code like this:
I'll let @tschuehly comment on how that would look with JTE. :-) |
The |
I've started a PR, for now JTE works with ModelAndView. I'll probably have time again in a couple weeks to continue. If anyone wants to join in! |
I propose adding a HtmxEndpoint Class that can be used to create HTTP Endpoints and can be directly called from Template Engines.
The Controller would look like this:
The class would like this:
In the template you would call it like this in Thymeleaf:
And this template would render like this:
Of course, the HtmxEndpoint could be expanded to all the possible Htmx attributes.
The Endpoints would be scanned at Startup using Reflection and added to the Spring RouterFunction
The text was updated successfully, but these errors were encountered: