Skip to content

Commit eb81b87

Browse files
committed
Add additional documentation about Collection<ModelAndView>
1 parent 73d041e commit eb81b87

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ public View users(Model model) {
193193
}
194194
```
195195

196+
Example with `Collection<ModelAndView>`:
197+
198+
```java
199+
@HxRequest
200+
@GetMapping("/users")
201+
public Collection<ModelAndView> users() {
202+
return List.of(
203+
new ModelAndView("users/list", Map.of("users", userRepository.findAll())),
204+
new ModelAndView("users/count", Map.of("count", userRepository.count()))
205+
);
206+
}
207+
```
208+
209+
196210
### Exceptions
197211

198212
It is also possible to use `HtmxRequest` and `HtmxResponse` as method argument in handler methods annotated with `@ExceptionHandler`.
@@ -208,6 +222,16 @@ public String handleError(Exception ex, HtmxRequest htmxRequest, HtmxResponse ht
208222
}
209223
```
210224

225+
It is also possible to add annotations on an exception handler to set response headers.
226+
227+
```java
228+
@ExceptionHandler(Exception.class)
229+
@HxRetarget("#error-message")
230+
public String handleError(Exception ex) {
231+
return "error";
232+
}
233+
```
234+
211235
### Spring Security
212236

213237
The library has an `HxRefreshHeaderAuthenticationEntryPoint` that you can use to have htmx force a full page browser
@@ -257,6 +281,20 @@ public View users(Model model) {
257281
}
258282
```
259283

284+
This is also possible using `Collection<ModelAndView` as return type:
285+
286+
```java
287+
@HxRequest
288+
@GetMapping("/users")
289+
public Collection<ModelAndView> test() {
290+
return List.of(
291+
new ModelAndView("users :: list", Map.of("users", userRepository.findAll())),
292+
new ModelAndView("users :: count", Map.of("count", userRepository.count()))
293+
);
294+
}
295+
296+
```
297+
260298
#### Dialect
261299

262300
The Thymeleaf dialect has appropriate processors that enable Thymeleaf to perform calculations and expressions
@@ -320,6 +358,7 @@ You can use multiple values like this:
320358

321359
Links to articles and blog posts about this library:
322360

361+
* [Redirect attributes with Spring MVC and htmx](https://www.wimdeblauwe.com/blog/2024/11/19/redirect-attributes-with-spring-mvc-and-htmx/)
323362
* [Release 1.0.0 and 2.0.0 of htmx-spring-boot-thymeleaf](https://www.wimdeblauwe.com/blog/2022/12/11/release-1.0.0-and-2.0.0-of-htmx-spring-boot-thymeleaf/)
324363
* [Htmx authentication error handling](https://www.wimdeblauwe.com/blog/2022/10/04/htmx-authentication-error-handling/)
325364
* [Thymeleaf and htmx with out of band swaps](https://www.wimdeblauwe.com/blog/2022/06/15/thymeleaf-and-htmx-with-out-of-band-swaps/)

0 commit comments

Comments
 (0)