From eecde02ee5dad7424d5b5ee6b6b71b8c5279a7aa Mon Sep 17 00:00:00 2001 From: xhaggi Date: Fri, 25 Oct 2024 11:18:55 +0200 Subject: [PATCH] Add static convenience methods to simplify creation of HtmxResponse.Builder --- .../htmx/spring/boot/mvc/HtmxResponse.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxResponse.java b/htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxResponse.java index 27a968d..9895c2b 100644 --- a/htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxResponse.java +++ b/htmx-spring-boot/src/main/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxResponse.java @@ -44,6 +44,77 @@ public static Builder builder() { return new Builder(); } + /** + * Can be used to do a client-side redirect to a new location. + * + * @param url the URL. Can be a relative or an absolute url + * @return the builder + */ + public static Builder redirect(String url) { + return new Builder().redirect(url); + } + + /** + * If set to "true" the client side will do a full refresh of the page + * + * @return the builder + */ + public static Builder refresh() { + return new Builder().refresh(); + } + + /** + * Append a view name to be resolved with {@code ViewResolver} implementations and used together with the implicit model. + * + * @param viewName the name of the view. + * @return the builder + */ + public static Builder view(String viewName) { + return new Builder().view(viewName); + } + + /** + * Append a {@link ModelAndView} instance to use for rendering. + * + * @param modelAndView the model and view + * @return the builder + */ + public static Builder view(ModelAndView modelAndView) { + return new Builder().view(modelAndView); + } + + /** + * Append a {@link View} instance to use for rendering together with the implicit model. + * + * @param view the view + * @return the builder + */ + public static Builder view(View view) { + return new Builder().view(view); + } + + /** + * Allows you to do a client-side redirect that does not do a full page reload. + * + * @param path the path + * @return the builder + * @see HX-Location Response Header + */ + public Builder location(String path) { + return new Builder().location(path); + } + + /** + * Allows you to do a client-side redirect that does not do a full page reload. + * + * @param location the location + * @return the builder + * @see HX-Location Response Header + */ + public Builder location(HtmxLocation location) { + return new Builder().location(location); + } + /** * @deprecated use {@link #builder()} instead. Will be removed in 4.0. */