Class HtmxResponse


  • public final class HtmxResponse
    extends java.lang.Object
    Representation of HTMX partials.
    Author:
    Oliver Drotbohm, Clint Checketts
    • Constructor Detail

      • HtmxResponse

        public HtmxResponse()
    • Method Detail

      • addTemplate

        public HtmxResponse addTemplate​(java.lang.String template)
        Append the rendered template or fragment.
        Parameters:
        template - must not be null or empty.
        Returns:
        same HtmxResponse for chaining
      • addTrigger

        public HtmxResponse addTrigger​(java.lang.String eventName)
        Set a HX-Trigger header. Multiple trigger were automatically be merged into the same header.
        Parameters:
        eventName - must not be null or empty.
        Returns:
        same HtmxResponse for chaining
        See Also:
        HX-Trigger Response Headers
      • addTrigger

        public HtmxResponse addTrigger​(java.lang.String eventName,
                                       java.lang.String eventDetail,
                                       HxTriggerLifecycle step)
        Set a HX-Trigger (or HX-Trigger-After-Settle or HX-Trigger-After-Swap headers. Multiple trigger were automatically be merged into the same header.
        Parameters:
        eventName - must not be null or empty.
        eventDetail - can be null.
        step - must not be null or empty.
        Returns:
        same HtmxResponse for chaining
        See Also:
        HX-Trigger Response Headers
      • pushHistory

        public HtmxResponse pushHistory​(java.lang.String url)
        Pushes a new url into the history stack
        Parameters:
        url - must not be null or empty. false prevents the browser history from being updated
        Returns:
        same HtmxResponse for chaining
        See Also:
        HX-Push Response Header documentation
      • browserRedirect

        public HtmxResponse browserRedirect​(java.lang.String url)
        Can be used to do a client-side redirect to a new location
        Parameters:
        url - can be a relative or an absolute url
        Returns:
        same HtmxResponse for chaining
      • browserRefresh

        public HtmxResponse browserRefresh​(boolean refresh)
        If set to "true" the client side will do a a full refresh of the page
        Parameters:
        refresh - boolean to indicate full refresh or not.
        Returns:
        same HtmxResponse for chaining
      • retarget

        public HtmxResponse retarget​(java.lang.String cssSelector)
        Set a CSS selector that updates the target of the content update to a different element on the page
        Parameters:
        cssSelector - must not be null or empty.
        Returns:
        same HtmxResponse for chaining
      • and

        public HtmxResponse and​(HtmxResponse otherResponse)
        Parameters:
        otherResponse - Another HtmxResponse that will be merged into this response.
        Returns:
        this for chaining