Class JsTrigger

java.lang.Object
com.vaadin.flow.component.trigger.AbstractTrigger
com.vaadin.flow.component.trigger.JsTrigger
All Implemented Interfaces:
Trigger, Serializable

public class JsTrigger extends AbstractTrigger
Trigger backed by an arbitrary JavaScript expression — the escape hatch for cases not covered by a built-in AbstractTrigger.

The expression is evaluated once during bind with the host element as this and a single named parameter trigger — a function the expression must call (synchronously, inside a DOM event handler) to fire the trigger. The expression may return a cleanup function; if it does, the cleanup runs when the trigger is removed or when the host is re-bound.


 new JsTrigger(host, "this.addEventListener('dblclick', trigger);"
         + "return () => this.removeEventListener('dblclick', trigger);")
         .triggers(action);
 
See Also:
  • Field Details

  • Constructor Details

    • JsTrigger

      public JsTrigger(Element host, String expression)
      Creates a JS-backed trigger on the given host element.
      Parameters:
      host - the host element, not null
      expression - the JS source, not null
    • JsTrigger

      public JsTrigger(Component host, String expression)
      Creates a JS-backed trigger on the given component's root element.
      Parameters:
      host - the host component, not null
      expression - the JS source, not null
  • Method Details

    • getExpression

      public String getExpression()
      Returns:
      the JS expression
    • buildClientConfig

      public tools.jackson.databind.node.ObjectNode buildClientConfig(ConfigContext context)
      Description copied from class: AbstractTrigger
      Produces the JSON configuration this trigger sends to the client. Default is an empty object; override to add type-specific options.

      The context lets subclasses encode element/output references by id when needed. Public so the internal framework can read the config without reflection; subclasses just override.

      Overrides:
      buildClientConfig in class AbstractTrigger
      Parameters:
      context - the resolver for referenced elements and outputs, not null
      Returns:
      a Jackson ObjectNode, never null