Class HtmxResponse.Builder

java.lang.Object
io.github.wimdeblauwe.htmx.spring.boot.mvc.HtmxResponse.Builder
Enclosing class:
HtmxResponse

public static final class HtmxResponse.Builder extends Object
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • and

      public HtmxResponse.Builder and(HtmxResponse otherResponse)
      Merges another HtmxResponse into this builder.
      Parameters:
      otherResponse - Another HtmxResponse that will be merged into this response.
      Returns:
      the builder
    • build

      public HtmxResponse build()
    • location

      public HtmxResponse.Builder location(String path)
      Allows you to do a client-side redirect that does not do a full page reload.
      Parameters:
      path - the path
      Returns:
      the builder
      See Also:
    • location

      public HtmxResponse.Builder location(HtmxLocation location)
      Allows you to do a client-side redirect that does not do a full page reload.
      Parameters:
      location - the location
      Returns:
      the builder
      See Also:
    • preventHistoryUpdate

      public HtmxResponse.Builder preventHistoryUpdate()
      Prevents the browser history stack from being updated.
      Returns:
      the builder
      See Also:
    • pushUrl

      public HtmxResponse.Builder pushUrl(String url)
      Pushes a new URL into the history stack of the browser.

      If you want to prevent the history stack from being updated, use preventHistoryUpdate().

      Parameters:
      url - the URL to push into the history stack. The URL can be any URL in the same origin as the current URL.
      Returns:
      the builder
      See Also:
    • redirect

      public HtmxResponse.Builder redirect(String url)
      Can be used to do a client-side redirect to a new location
      Parameters:
      url - the URL. Can be a relative or an absolute url
      Returns:
      the builder
    • refresh

      public HtmxResponse.Builder refresh()
      If set to "true" the client side will do a full refresh of the page
      Returns:
      the builder
    • replaceUrl

      public HtmxResponse.Builder replaceUrl(String url)
      Allows you to replace the most recent entry, i.e. the current URL, in the browser history stack.

      If you want to prevent the history stack from being updated, use preventHistoryUpdate().

      Parameters:
      url - the URL to replace in the history stack. The URL can be any URL in the same origin as the current URL.
      Returns:
      the builder
      See Also:
    • reswap

      public HtmxResponse.Builder reswap(HtmxReswap reswap)
      Set a new swap to specify how the response will be swapped.
      Parameters:
      reswap - the reswap options.
      Returns:
      the builder
    • retarget

      public HtmxResponse.Builder retarget(String cssSelector)
      Set a CSS selector that updates the target of the content update to a different element on the page
      Parameters:
      cssSelector - the CSS selector
      Returns:
      the builder
    • reselect

      public HtmxResponse.Builder reselect(String cssSelector)
      Set a CSS selector that allows you to choose which part of the response is used to be swapped in. Overrides an existing hx-select on the triggering element.
      Parameters:
      cssSelector - the CSS selector
      Returns:
      the builder
    • trigger

      public HtmxResponse.Builder trigger(String eventName)
      Adds an event that will be triggered once the response is received.

      Multiple trigger were automatically be merged into the same header.

      Parameters:
      eventName - the event name
      Returns:
      the builder
      See Also:
    • trigger

      public HtmxResponse.Builder trigger(String eventName, Object eventDetail)
      Adds an event that will be triggered once the response is received.

      Multiple trigger were automatically be merged into the same header.

      Parameters:
      eventName - the event name
      eventDetail - details along with the event
      Returns:
      the builder
      See Also:
    • triggerAfterSettle

      public HtmxResponse.Builder triggerAfterSettle(String eventName)
      Adds an event that will be triggered after the settling step.

      Multiple triggers were automatically be merged into the same header.

      Parameters:
      eventName - the event name
      Returns:
      the builder
      See Also:
    • triggerAfterSettle

      public HtmxResponse.Builder triggerAfterSettle(String eventName, Object eventDetail)
      Adds an event that will be triggered after the settling step.

      Multiple triggers were automatically be merged into the same header.

      Parameters:
      eventName - the event name
      eventDetail - details along with the event
      Returns:
      the builder
      See Also:
    • triggerAfterSwap

      public HtmxResponse.Builder triggerAfterSwap(String eventName)
      Adds an event that will be triggered after the swap step.

      Multiple triggers were automatically be merged into the same header.

      Parameters:
      eventName - the event name
      Returns:
      the builder
      See Also:
    • triggerAfterSwap

      public HtmxResponse.Builder triggerAfterSwap(String eventName, Object eventDetail)
      Adds an event that will be triggered after the swap step.

      Multiple triggers were automatically be merged into the same header.

      Parameters:
      eventName - the event name
      eventDetail - details along with the event
      Returns:
      the builder
      See Also:
    • view

      public HtmxResponse.Builder view(String viewName)
      Append a view name to be resolved with ViewResolver implementations and used together with the implicit model.
      Parameters:
      viewName - the name of the view.
      Returns:
      the builder
    • view

      public HtmxResponse.Builder view(org.springframework.web.servlet.View view)
      Append a View instance to use for rendering together with the implicit model.
      Parameters:
      view - the view
      Returns:
      the builder
    • view

      public HtmxResponse.Builder view(org.springframework.web.servlet.ModelAndView modelAndView)
      Append a ModelAndView instance to use for rendering.
      Parameters:
      modelAndView - the model and view
      Returns:
      the builder