Class WebXElement

java.lang.Object
webx.WebXElement
Direct Known Subclasses:
Area, Br, Col, Embed, Hr, Img, Input, Link, Meta, Param, Path, Script, Source, Track, WebXContainerElement

public abstract class WebXElement extends Object
Represents a basic HTML element. All UI Nodes extend this.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected WebXAttributes
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    attr(String key, String value)
    Adds an attribute to the element
    The class global attribute is a list of the classes of the element, separated by ASCII whitespace.
    hxBoost(boolean activate)
    The hxBoost attribute allows you to “boost” normal anchors and form tags to use AJAX instead.
    hxConfirm(String message)
    The hxConfirm method allows you to confirm an action before issuing a request.
    Submits a file uploaded via a form to the server.
    Submits a file uploaded via a form to the server
    The hxExt attribute enables an htmx extension for an element and all its children.
    hxGet(String path)
    The hxGet method will cause an element to issue a GET to the specified URL and swap the HTML into the DOM using a swap strategy
    hxOn(String event)
    The hxOn method allow you to embed scripts inline to respond to events directly on an element; similar to the onevent properties found in HTML, such as onClick.
    hxPost(String path)
    The hxPost method will cause an element to issue a POST to the specified URL and swap the HTML into the DOM using a swap strategy
    Sends a message to the nearest websocket based on the trigger value for the element
    hxSwap(String strategy)
    The hx-swap attribute allows you to specify how the response will be swapped in relative to the target of an AJAX request.
    The hx-swap-oob attribute allows you to specify that some content in a response should be swapped into the DOM somewhere other than the target, that is “Out of Band”.
    hxTarget(String target)
    The hx-target attribute allows you to target a different element for swapping than the one issuing the AJAX request.
    hxTrigger(String trigger)
    The hx-trigger attribute allows you to specify what triggers an AJAX request.
    The hx-vals attribute allows you to add to the parameters that will be submitted with an AJAX request.
    hxWs(String url)
    The WebSockets extension enables easy, bi-directional communication with Web Sockets servers directly from HTML.
    id(String id)
    The id global attribute defines an identifier (ID) which must be unique in the whole document.
    abstract String
    Converts the Any webx element into its html representation, including all its children, recursively.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • WebXElement

      public WebXElement()
  • Method Details

    • attr

      public WebXElement attr(String key, String value)
      Adds an attribute to the element
      Parameters:
      key - The attribute identifier or name
      value - The attribute value
      Returns:
      A modified element
    • hxVals

      public WebXElement hxVals(String val)
      The hx-vals attribute allows you to add to the parameters that will be submitted with an AJAX request.
      Parameters:
      val - Custom data to be send to the server along with the request. Useful when sending post requests.
      Returns:
      A modified element
      See Also:
      • htmx docs
         
         	new P()
         		.hxVals("{\"myVal\": 100}");
         	new P()
         		.hxVals("js:{\"compute\": 100 * 5 * somevar}");
         
         
    • hxTrigger

      public WebXElement hxTrigger(String trigger)
      The hx-trigger attribute allows you to specify what triggers an AJAX request.
      Parameters:
      trigger - The event that triggers the http request
      Returns:
      A modified element
      See Also:
      • htmx docs
         
         	new P("00:00:00")
         		.hxPost("/get_clock")
         		.hxTrigger("every 1s");
         
         
    • hxTarget

      public WebXElement hxTarget(String target)
      The hx-target attribute allows you to target a different element for swapping than the one issuing the AJAX request.
      Parameters:
      target - The target element to be replaced with the response html
      Returns:
      A modified element
      See Also:
      • htmx docs
         
         	new Button("Click Me")
         		.hxPost("/greet)
         		.hxTarget("#parentdiv");
         
         
    • hxSwap

      public WebXElement hxSwap(String strategy)
      The hx-swap attribute allows you to specify how the response will be swapped in relative to the target of an AJAX request. If you do not specify the option, the default is htmx.config.defaultSwapStyle (innerHTML).
      Parameters:
      strategy - The swap strategy to be used
      Returns:
      A modified element
      See Also:
      • htmx docs
         
         	new Button("Click Me")
         		.hxPost("/greet)
         		.hxSwap("outerHTML");
         
         
    • hxSwapOob

      public WebXElement hxSwapOob(String value)
      The hx-swap-oob attribute allows you to specify that some content in a response should be swapped into the DOM somewhere other than the target, that is “Out of Band”. This allows you to piggy back updates to other element updates on a response.
      Parameters:
      value - Activation (true) or a swap strategy
      Returns:
      A modified element
      See Also:
      • htmx docs
         
         	new Button("Click Me")
         		.hxPost("/greet)
         		.hxSwapOob("true");
         
         
    • hxEncoding

      public WebXElement hxEncoding(String type)
      Submits a file uploaded via a form to the server
      Parameters:
      type - The type of encoding which must be used. Note custom encoding formats are not yet supported for now.
      Returns:
      A modified element
      See Also:
    • hxEncoding

      public WebXElement hxEncoding()
      Submits a file uploaded via a form to the server. Sets the the type to "multipart/form-data"
      Returns:
      A modified element
      See Also:
    • hxOn

      public WebXElement hxOn(String event)
      The hxOn method allow you to embed scripts inline to respond to events directly on an element; similar to the onevent properties found in HTML, such as onClick. The hx-on* attributes improve upon onevent by enabling the handling of any arbitrary JavaScript event, for enhanced Locality of Behaviour (LoB) even when dealing with non-standard DOM events
      Parameters:
      event - Event which triggers the requests
      Returns:
      A modified element
      See Also:
    • hxPost

      public WebXElement hxPost(String path)
      The hxPost method will cause an element to issue a POST to the specified URL and swap the HTML into the DOM using a swap strategy
      Parameters:
      path - Server endpoint to make the request to
      Returns:
      A modified element
      See Also:
    • hxGet

      public WebXElement hxGet(String path)
      The hxGet method will cause an element to issue a GET to the specified URL and swap the HTML into the DOM using a swap strategy
      Parameters:
      path - Server endpoint to make the request to
      Returns:
      A modified element
      See Also:
    • hxBoost

      public WebXElement hxBoost(boolean activate)
      The hxBoost attribute allows you to “boost” normal anchors and form tags to use AJAX instead.
      Parameters:
      activate - The boolean value used to enable or disable the boost
      Returns:
      A modified element
      See Also:
    • hxConfirm

      public WebXElement hxConfirm(String message)
      The hxConfirm method allows you to confirm an action before issuing a request. This can be useful in cases where the action is destructive and you want to ensure that the user really wants to do it.
      Parameters:
      message - Text to be used as a confirmation message
      Returns:
      A modified element
      See Also:
    • hxExt

      public WebXElement hxExt(String ext)
      The hxExt attribute enables an htmx extension for an element and all its children. The value can be a single extension name or a comma separated list of extensions to apply. The hxExt tag may be placed on parent elements if you want a plugin to apply to an entire swath of the DOM, and on the body tag for it to apply to all htmx requests.
      Parameters:
      ext - The extension to be used
      Returns:
      A modified element
      See Also:
    • hxWs

      public WebXElement hxWs(String url)
      The WebSockets extension enables easy, bi-directional communication with Web Sockets servers directly from HTML.
      Parameters:
      url - Url for the websocket server
      Returns:
      A modified element
      See Also:
    • hxSend

      public WebXElement hxSend()
      Sends a message to the nearest websocket based on the trigger value for the element
      Returns:
      A modified element
      See Also:
    • id

      public WebXElement id(String id)
      The id global attribute defines an identifier (ID) which must be unique in the whole document. The purpose of the ID attribute is to identify a single element when linking (using a fragment identifier), scripting, or styling (with CSS). Elements with ID attributes are available as global properties. The property name is the ID attribute, and the property value is the element.
      Parameters:
      id - The identifier for the element
      Returns:
      A modified element
      See Also:
    • className

      public WebXElement className(String names)
      The class global attribute is a list of the classes of the element, separated by ASCII whitespace. Classes allow CSS and JavaScript to select and access specific elements via the class selectors or functions like the document.getElementsByClassName().
      Parameters:
      names - Whitespace separated list of classes
      Returns:
      A modified element
      See Also:
    • render

      public abstract String render()
      Converts the Any webx element into its html representation, including all its children, recursively.
      Returns:
      The String representation of the element along with the children.