Class AbstractTrigger

java.lang.Object
com.vaadin.flow.component.trigger.AbstractTrigger
All Implemented Interfaces:
Trigger, Serializable
Direct Known Subclasses:
ClickTrigger, JsTrigger, ShortcutTrigger

public abstract class AbstractTrigger extends Object implements Trigger
Base class for Trigger implementations.

Subclasses identify themselves with a namespaced type id ("flow:click", "myapp:double-tap", …) which must match a factory registered against window.Vaadin.Flow.triggers on the client side. Subclasses override buildClientConfig(com.vaadin.flow.component.trigger.internal.ConfigContext) when they need to ship extra configuration with the trigger.

See Also:
  • Constructor Details

    • AbstractTrigger

      protected AbstractTrigger(String typeId, Element host)
      Creates a new trigger bound to the given host element.
      Parameters:
      typeId - namespaced type id matching a client factory, not null
      host - the element the trigger fires on, not null
    • AbstractTrigger

      protected AbstractTrigger(String typeId, Component host)
      Creates a new trigger bound to the given host component's root element.
      Parameters:
      typeId - namespaced type id matching a client factory, not null
      host - the component whose root element the trigger fires on, not null
  • Method Details

    • getHost

      public final Element getHost()
      The host element this trigger fires on.
      Returns:
      the host element, never null
    • getTypeId

      public final String getTypeId()
      The namespaced type id of this trigger.
      Returns:
      the type id, never null
    • getTriggerId

      public final int getTriggerId()
      Internal id for this trigger within its host's TriggerSupport.
      Returns:
      the id
    • buildClientConfig

      public tools.jackson.databind.node.ObjectNode buildClientConfig(ConfigContext context)
      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.

      Parameters:
      context - the resolver for referenced elements and outputs, not null
      Returns:
      a Jackson ObjectNode, never null
    • triggers

      public final Trigger triggers(Action... actions)
      Description copied from interface: Trigger
      Wires the given actions to this trigger. They run in the order given, inside the original DOM event handler, the next time this trigger fires.
      Specified by:
      triggers in interface Trigger
      Parameters:
      actions - the actions to run, not null
      Returns:
      this trigger, for chaining
    • triggers

      public final Trigger triggers(SerializableRunnable serverHandler)
      Description copied from interface: Trigger
      Wires a server-side callback to this trigger. The callback runs after the client-side dispatch of any other bound actions has finished. The callback fires on the UI thread.

      This is sugar for adding a ServerCallbackAction that wraps the given runnable.

      Specified by:
      triggers in interface Trigger
      Parameters:
      serverHandler - the runnable to execute on the server, not null
      Returns:
      this trigger, for chaining
    • remove

      public final void remove()
      Description copied from interface: Trigger
      Removes this trigger and all bindings created from it. The corresponding client-side handlers are detached as part of the next synchronisation.
      Specified by:
      remove in interface Trigger