Package rife.engine

Class HxLocation

java.lang.Object
rife.engine.HxLocation

public class HxLocation extends Object
Describes an htmx client-side navigation together with its context, for the JSON form of the HX-Location response header.

When a location only carries a path, it will be sent as the plain path string, exactly like Context.hxLocation(String) does. As soon as you add any piece of context, the header switches over to htmx's JSON object form:

c.hxLocation(new HxLocation(books).target("#main").swap("outerHTML"));

which sends:

HX-Location: {"path":"/books","target":"#main","swap":"outerHTML"}
Since:
1.10
See Also:
  • Constructor Details

    • HxLocation

      public HxLocation(String path)
      Creates a location that navigates to a URL.
      Parameters:
      path - the URL to navigate to
      Since:
      1.10
      See Also:
    • HxLocation

      public HxLocation(Route route)
      Creates a location that navigates to a route.

      The URL of the route will only be resolved when the header is set, so that the navigation survives renaming and refactoring.

      Parameters:
      route - the route to navigate to
      Since:
      1.10
      See Also:
  • Method Details

    • source

      public HxLocation source(String cssSelector)
      Sets the element that is the source of the navigation request.
      Parameters:
      cssSelector - the CSS selector of the source element
      Returns:
      this HxLocation instance, so that method calls can be chained
      Since:
      1.10
    • event

      public HxLocation event(String event)
      Sets the event that will trigger the navigation request.
      Parameters:
      event - the name of the event
      Returns:
      this HxLocation instance, so that method calls can be chained
      Since:
      1.10
    • target

      public HxLocation target(String cssSelector)
      Sets the element that the response will be swapped into.
      Parameters:
      cssSelector - the CSS selector of the target element
      Returns:
      this HxLocation instance, so that method calls can be chained
      Since:
      1.10
    • swap

      public HxLocation swap(String swapStyle)
      Sets the way in which the response will be swapped in.

      This takes an hx-swap value, for instance outerHTML or beforeend.

      Parameters:
      swapStyle - the swap style to use
      Returns:
      this HxLocation instance, so that method calls can be chained
      Since:
      1.10
    • select

      public HxLocation select(String cssSelector)
      Selects only a part of the response for swapping.
      Parameters:
      cssSelector - the CSS selector to select from the response
      Returns:
      this HxLocation instance, so that method calls can be chained
      Since:
      1.10
    • values

      public HxLocation values(Object values)
      Sets the values that will be submitted with the navigation request.

      The values will be serialized to JSON with RIFE2's own Json support, so that records, beans and maps all work.

      Parameters:
      values - the values to submit
      Returns:
      this HxLocation instance, so that method calls can be chained
      Since:
      1.10
    • headers

      public HxLocation headers(Map<String,String> headers)
      Sets the headers that will be submitted with the navigation request.
      Parameters:
      headers - the headers to submit
      Returns:
      this HxLocation instance, so that method calls can be chained
      Since:
      1.10