java.lang.Object
com.vaadin.flow.component.trigger.internal.Action
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CallbackAction, DownloadAction, OpenInNewTabAction, PromiseAction, SetPropertyAction

public abstract class Action extends Object implements Serializable
Something that runs on the client when a Trigger fires.

Actions are the unit of behaviour you attach to a trigger: copy text to the clipboard, download a file, scroll an element into view, and so on. Pair an Action with a Trigger (typically via trigger.triggers(action)) and the framework wires the action to run whenever the trigger fires.

An Action usually consumes one or more inputs that supply its values — a literal, the current value of a DOM property, an event-scoped expression — so the data the action acts on is read on the client at fire time rather than captured on the server. A trigger family may expose its event state as one or more Inputs, typically as public static final fields (for example MouseEventTrigger.EventData.screenX); other inputs read state independent of any trigger (for example PropertyInput).

For Action implementors: override toJs(Trigger) to produce the JavaScript that the trigger handler invokes; reference inputs through Action.Input.toJs(Trigger) so the same value-supplier abstractions work with every action.

For internal use only. May be renamed or removed in a future release.

Since:
25.2
See Also:
  • Constructor Details

    • Action

      public Action()
  • Method Details

    • toJs

      protected abstract JsFunction toJs(Trigger trigger)
      Builds the JsFunction that runs this action when the surrounding trigger fires. The returned function takes two runtime arguments: event, the client event that fired the trigger, and context, the trigger context — an object describing what the trigger fired for, or undefined for triggers that have no such notion. A SinkTrigger rendered into a client-side template, for example, supplies {args}, the arguments the template called the action with, which is what lets one action serve every element a renderer draws.

      The body is one statement. To embed a value produced on the client, capture an Action.Input's JsFunction as a capture and invoke it inside the body as $N(event, context) — always forwarding both arguments, so inputs that read the context work in every action.

      Parameters:
      trigger - the surrounding trigger this render is for, not null
      Returns:
      the action's JS function, not null
    • warnIfNotVisible

      protected static void warnIfNotVisible(Component target, String actionDescription)
      Logs a warning if target is not visible. Intended for actions that capture another component's element as a JsFunction reference: an invisible component is not sent to the client, the captured element reference resolves to null when the install JS runs, and the action fails at fire time. JsFunction captures are bound by value at install time, so restoring visibility later does not recover the binding.

      Call this after the target is known to be attached (typically inside a runWhenAttached callback) so the check sees the visibility state at the time the install JS would be sent to the client.

      Parameters:
      target - the component whose visibility to check, not null
      actionDescription - human-readable name of the action being wired, used in the warning message (e.g. "Fullscreen.enter()"), not null