tschuehly / spring-view-component

Server-side UI components with spring boot
MIT License
174 stars 8 forks source link

Proposal: Add HxTrigger #11

Closed don41382 closed 1 month ago

don41382 commented 10 months ago

First and most important: Thank you for building the awesome plugin. I think the combination Spring + JTE +. htmx has huge potential!

I was wondering, what you would think about a @HxTrigger annotation, like htmx-spring-boot has included: https://github.com/wimdeblauwe/htmx-spring-boot#response-headers

This is quite nice to have.

tschuehly commented 10 months ago

What do you want to do with HxTrigger? In my new project I am using htmx-spring-boot in combination with Spring ViewComponent and it pairs nicely.

don41382 commented 10 months ago

Ah, I didn't know that you can pair them. I will give this a try. That would make the need for HxTriggers obsolet. I wanted to trigger a refresh for certain parts, when it's not directly related to the triggering change. A user adds a todo to the list, the list refreshes (inside a different component)

Do you already know when 0.7. will be ready?

tschuehly commented 10 months ago

0.7 is mostly done but I will change the template context still a bit as I want to only pass in the record to the template and not just the properties.

But you can use 0.7-SNAPSHOT already as the tests are already passing. You can look at the example folder for a usage of the new record syntax.

don41382 commented 10 months ago

Yes, I am already on that branch and made my first test app. I like the kte and the new record / template style. I had the same thought about passing just the record (data class) into the template.

Tonight I am going to try to add htmx-spring-boot.

On Thu, 14 Sept 2023 at 23:49, Thomas Schühly @.***> wrote:

0.7 is mostly done but I will change the template context still a bit as I want to only pass in the record to the template and not just the properties.

But you can use 0.7-SNAPSHOT already as the tests are already passing. You can look at the example folder for a usage of the new record syntax.

— Reply to this email directly, view it on GitHub https://github.com/tschuehly/spring-view-component/issues/11#issuecomment-1720198977, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANP2PEKDK6VRNEVPDILBPDX2N3W3ANCNFSM6AAAAAA4YS7V7A . You are receiving this because you authored the thread.Message ID: @.***>

don41382 commented 10 months ago

I just added the dependency (implementation("io.github.wimdeblauwe:htmx-spring-boot:3.0.0")) and get the following error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'viewActionConfiguration' defined in URL [jar:file:/Users/felixeckhardt/.m2/repository/de/tschuehly/spring-view-component-core/0.7.0-SNAPSHOT/spring-view-component-core-0.7.0-SNAPSHOT.jar!/de/tschuehly/spring/viewcomponent/core/action/ViewActionConfiguration.class]: Unsatisfied dependency expressed through constructor parameter 1: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]: Failed to instantiate [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]: Factory method 'requestMappingHandlerMapping' threw exception with message: No qualifying bean of type 'org.springframework.web.servlet.ViewResolver' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier("viewResolver")}

Maybe you have an idea.

tschuehly commented 10 months ago

Can you post an example repo? I could not reproduce the error locally in the kte example: https://github.com/tschuehly/spring-view-component/tree/v0.7.0-SNAPSHOT/examples/kte-example

don41382 commented 10 months ago

Here is my playground. It's a little e-mail address playground app. If you have any tips on how to improve it, please let me know: https://github.com/don41382/htmxjetdemo

I compared your and my project. After removing @EnableWebMvc the exception on startup was gone. Thanks for the help.

I also added a few questions to the project:

tschuehly commented 10 months ago

I have to take a look at supporting @PathVariable with ViewActions.

I removed the EmptyContext as the template resolving is based the enclosing class of the data class/record

tschuehly commented 1 month ago

Hey there,

I removed the ViewActions from Spring ViewComponent in v0.8.0, as there is a better approach and the Annotation Processor added a lot of complexity.

The goal is to create a functional approach for HTMX Endpoints described here in an extension at a later date: https://github.com/wimdeblauwe/htmx-spring-boot/issues/104

btw, you can add @ViewComponent and @Controller on the same class.