Skip to content

Commit 07ac875

Browse files
committed
Remove annotations HxRefresh, HxRedirect and HxLocation in favor of special views
See https://github.com/wimdeblauwe/htmx-spring-boot?tab=readme-ov-file#special-view-name-prefixes
1 parent f73c918 commit 07ac875

File tree

6 files changed

+0
-240
lines changed

6 files changed

+0
-240
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ public String user(@PathVariable Long id, @ModelAttribute @Valid UserForm form,
147147

148148
The following annotations can be used on controller methods to set the necessary response headers.
149149

150-
* [@HxLocation](https://javadoc.io/doc/io.github.wimdeblauwe/htmx-spring-boot/latest/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxLocation.html)
151150
* [@HxPushUrl](https://javadoc.io/doc/io.github.wimdeblauwe/htmx-spring-boot/latest/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxPushUrl.html)
152-
* [@HxRedirect](https://javadoc.io/doc/io.github.wimdeblauwe/htmx-spring-boot/latest/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxRedirect.html)
153-
* [@HxRefresh](https://javadoc.io/doc/io.github.wimdeblauwe/htmx-spring-boot/latest/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxRefresh.html)
154151
* [@HxReplaceUrl](https://javadoc.io/doc/io.github.wimdeblauwe/htmx-spring-boot/latest/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxReplaceUrl.html)
155152
* [@HxReselect](https://javadoc.io/doc/io.github.wimdeblauwe/htmx-spring-boot/latest/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxReselect.html)
156153
* [@HxReswap](https://javadoc.io/doc/io.github.wimdeblauwe/htmx-spring-boot/latest/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxReswap.html)

htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodHandler.java

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,14 @@ public void handleMethodArgument(HttpServletRequest request, HttpServletResponse
5454

5555
public void handleMethodAnnotations(Method method, HttpServletRequest request, HttpServletResponse response) {
5656

57-
setHxLocation(request, response, method);
5857
setHxPushUrl(request, response, method);
59-
setHxRedirect(request, response, method);
6058
setHxReplaceUrl(request, response, method);
6159
setHxReswap(response, method);
6260
setHxRetarget(response, method);
6361
setHxReselect(response, method);
6462
setHxTrigger(response, method);
6563
setHxTriggerAfterSettle(response, method);
6664
setHxTriggerAfterSwap(response, method);
67-
setHxRefresh(response, method);
6865
}
6966

7067
private void addHxTriggerHeaders(HttpServletResponse response, HtmxResponseHeader headerName, Collection<HtmxTrigger> triggers) {
@@ -90,19 +87,6 @@ private void addHxTriggerHeaders(HttpServletResponse response, HtmxResponseHeade
9087
setHeaderJsonValue(response, headerName, triggerMap);
9188
}
9289

93-
private void setHxLocation(HttpServletRequest request, HttpServletResponse response, Method method) {
94-
HxLocation methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, HxLocation.class);
95-
if (methodAnnotation != null) {
96-
var location = convertToLocation(methodAnnotation);
97-
if (location.hasContextData()) {
98-
location.setPath(RequestContextUtils.createUrl(request, location.getPath(), methodAnnotation.contextRelative()));
99-
setHeaderJsonValue(response, HtmxResponseHeader.HX_LOCATION, location);
100-
} else {
101-
setHeader(response, HtmxResponseHeader.HX_LOCATION, RequestContextUtils.createUrl(request, location.getPath(), methodAnnotation.contextRelative()));
102-
}
103-
}
104-
}
105-
10690
private void setHxPushUrl(HttpServletRequest request, HttpServletResponse response, Method method) {
10791
HxPushUrl methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, HxPushUrl.class);
10892
if (methodAnnotation != null) {
@@ -114,13 +98,6 @@ private void setHxPushUrl(HttpServletRequest request, HttpServletResponse respon
11498
}
11599
}
116100

117-
private void setHxRedirect(HttpServletRequest request, HttpServletResponse response, Method method) {
118-
HxRedirect methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, HxRedirect.class);
119-
if (methodAnnotation != null) {
120-
setHeader(response, HtmxResponseHeader.HX_REDIRECT, RequestContextUtils.createUrl(request, methodAnnotation.value(), methodAnnotation.contextRelative()));
121-
}
122-
}
123-
124101
private void setHxReplaceUrl(HttpServletRequest request, HttpServletResponse response, Method method) {
125102
HxReplaceUrl methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, HxReplaceUrl.class);
126103
if (methodAnnotation != null) {
@@ -174,13 +151,6 @@ private void setHxTriggerAfterSwap(HttpServletResponse response, Method method)
174151
}
175152
}
176153

177-
private void setHxRefresh(HttpServletResponse response, Method method) {
178-
HxRefresh methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, HxRefresh.class);
179-
if (methodAnnotation != null) {
180-
setHeader(response, HtmxResponseHeader.HX_REFRESH, HtmxValue.TRUE);
181-
}
182-
}
183-
184154
private void setHeader(HttpServletResponse response, HtmxResponseHeader header, String value) {
185155
response.setHeader(header.getValue(), value);
186156
}
@@ -189,30 +159,6 @@ private void setHeader(HttpServletResponse response, HtmxResponseHeader header,
189159
response.setHeader(header.getValue(), String.join(",", values));
190160
}
191161

192-
private HtmxLocation convertToLocation(HxLocation annotation) {
193-
var location = new HtmxLocation();
194-
location.setPath(annotation.path());
195-
if (!annotation.source().isEmpty()) {
196-
location.setSource(annotation.source());
197-
}
198-
if (!annotation.event().isEmpty()) {
199-
location.setEvent(annotation.event());
200-
}
201-
if (!annotation.handler().isEmpty()) {
202-
location.setHandler(annotation.handler());
203-
}
204-
if (!annotation.target().isEmpty()) {
205-
location.setTarget(annotation.target());
206-
}
207-
if (!annotation.target().isEmpty()) {
208-
location.setSwap(annotation.swap());
209-
}
210-
if (!annotation.select().isEmpty()) {
211-
location.setSelect(annotation.select());
212-
}
213-
return location;
214-
}
215-
216162
private String convertToReswap(HxReswap annotation) {
217163

218164
var reswap = new HtmxReswap(annotation.value());

htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxLocation.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxRedirect.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HxRefresh.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerInterceptorTest.java

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -111,41 +111,6 @@ public void testVaryNoHxRequest() throws Exception {
111111
.andExpect(header().stringValues("Vary", not(containsInRelativeOrder("HX-Request"))));
112112
}
113113

114-
@Test
115-
public void testHxRefresh() throws Exception {
116-
mockMvc.perform(get("/hx-refresh"))
117-
.andExpect(status().isOk())
118-
.andExpect(header().string("HX-Refresh", "true"));
119-
}
120-
121-
@Test
122-
public void testHxLocationWithContextData() throws Exception {
123-
mockMvc.perform(get("/hx-location-with-context-data"))
124-
.andExpect(status().isOk())
125-
.andExpect(header().string("HX-Location", "{\"path\":\"/path\",\"source\":\"source\",\"event\":\"event\",\"handler\":\"handler\",\"target\":\"target\",\"swap\":\"swap\",\"select\":\"select\"}"));
126-
}
127-
128-
@Test
129-
public void testHxLocationWithContextDataPathShouldPrependContextPath() throws Exception {
130-
mockMvc.perform(get("/test/hx-location-with-context-data").contextPath("/test"))
131-
.andExpect(status().isOk())
132-
.andExpect(header().string("HX-Location", "{\"path\":\"/test/path\",\"source\":\"source\",\"event\":\"event\",\"handler\":\"handler\",\"target\":\"target\",\"swap\":\"swap\",\"select\":\"select\"}"));
133-
}
134-
135-
@Test
136-
public void testHxLocationWithoutContextData() throws Exception {
137-
mockMvc.perform(get("/test/hx-location-without-context-data").contextPath("/test"))
138-
.andExpect(status().isOk())
139-
.andExpect(header().string("HX-Location", "/test/path"));
140-
}
141-
142-
@Test
143-
public void testHxLocationWithoutContextDataShouldPrependContextPath() throws Exception {
144-
mockMvc.perform(get("/test/hx-location-without-context-data").contextPath("/test"))
145-
.andExpect(status().isOk())
146-
.andExpect(header().string("HX-Location", "/test/path"));
147-
}
148-
149114
@Test
150115
public void testHxPushUrlPath() throws Exception {
151116
mockMvc.perform(get("/hx-push-url-path"))
@@ -174,20 +139,6 @@ public void testHxPushUrlShouldPrependContextPath() throws Exception {
174139
.andExpect(header().string("HX-Push-Url", "/test/path"));
175140
}
176141

177-
@Test
178-
public void testHxRedirect() throws Exception {
179-
mockMvc.perform(get("/hx-redirect"))
180-
.andExpect(status().isOk())
181-
.andExpect(header().string("HX-Redirect", "/path"));
182-
}
183-
184-
@Test
185-
public void testHxRedirectShouldPrependContextPath() throws Exception {
186-
mockMvc.perform(get("/test/hx-redirect").contextPath("/test"))
187-
.andExpect(status().isOk())
188-
.andExpect(header().string("HX-Redirect", "/test/path"));
189-
}
190-
191142
@Test
192143
public void testHxReplaceUrlPath() throws Exception {
193144
mockMvc.perform(get("/hx-replace-url-path"))
@@ -312,33 +263,12 @@ public String hxTriggerWithAliasForOverride() {
312263
return "";
313264
}
314265

315-
@GetMapping("/hx-refresh")
316-
@HxRefresh
317-
@ResponseBody
318-
public String hxRefresh() {
319-
return "";
320-
}
321-
322266
@GetMapping("/hx-vary")
323267
@ResponseBody
324268
public String hxVary() {
325269
return "";
326270
}
327271

328-
@GetMapping("/hx-location-without-context-data")
329-
@HxLocation("/path")
330-
@ResponseBody
331-
public String hxLocationWithoutContextData() {
332-
return "";
333-
}
334-
335-
@GetMapping("/hx-location-with-context-data")
336-
@HxLocation(path = "/path", source = "source", event = "event", handler = "handler", target = "target", swap = "swap", select = "select")
337-
@ResponseBody
338-
public String hxLocationWithContextData() {
339-
return "";
340-
}
341-
342272
@GetMapping("/hx-push-url-path")
343273
@HxPushUrl("/path")
344274
@ResponseBody
@@ -360,13 +290,6 @@ public String hxPushUrlFalse() {
360290
return "";
361291
}
362292

363-
@GetMapping("/hx-redirect")
364-
@HxRedirect("/path")
365-
@ResponseBody
366-
public String hxRedirect() {
367-
return "";
368-
}
369-
370293
@GetMapping("/hx-replace-url-path")
371294
@HxReplaceUrl("/path")
372295
@ResponseBody

0 commit comments

Comments
 (0)