htmx-spring-boot icon indicating copy to clipboard operation
htmx-spring-boot copied to clipboard

Remove annotation support for HX-Refresh, HX-Location and HX-Redirect

Open xhaggi opened this issue 1 year ago • 3 comments

I would like to discuss whether we should drop the annotations @HxRefresh, @HxLocation and @HxRedirect, as it makes no sense to me to use them in a controller method in combination with a view as a return value. This would also simplify our code base and make things less confusing.

@wimdeblauwe what do you think?

xhaggi avatar Nov 25 '24 17:11 xhaggi

Can you add an examples of how the code looks with the annotations and without? I will add a message on Twitter and Bluesky after that so people can give their opinion on this.

wimdeblauwe avatar Nov 25 '24 17:11 wimdeblauwe

Spring MVC support special prefix like "redirect:/" Maybe return a string "hx:refresh"

Alwan avatar Nov 30 '24 12:11 Alwan

I would like to discuss whether we should drop the annotations @HxRefresh, @HxLocation and @HxRedirect, as it makes no sense to me to use them in a controller method in combination with a view as a return value. This would also simplify our code base and make things less confusing.

I don't use these as I don't see a use case as a controller annotation.

resmo avatar Dec 02 '24 05:12 resmo

Can you add an examples of how the code looks with the annotations and without? I will add a message on Twitter and Bluesky after that so people can give their opinion on this.

@wimdeblauwe this is explained in the README.md#special-view-name-prefixes.

When using annotations, you can return a different view, such as template code, but the body of the response will be ignored by htmx. So instead of using the annotation you simple return one of the special view names or use one of the view classes as controller method return type.

Annotation View View Name
@HxRefresh HtmxRefreshView refresh:htmx
@HxRedirect HtmxRedirectView redirect:htmx:/path
@HxLocation HtmxLocationRedirectView redirect:htmx:location:/path

xhaggi avatar Sep 24 '25 10:09 xhaggi