Class JsAction

java.lang.Object
com.vaadin.flow.component.trigger.AbstractAction
com.vaadin.flow.component.trigger.JsAction
All Implemented Interfaces:
Action, Serializable

public class JsAction extends AbstractAction
Action backed by an arbitrary JavaScript expression — the escape hatch for cases not covered by a built-in AbstractAction.

The expression runs every time the trigger fires. A single helper is in scope: output(i) returns the resolved value of the i-th declared output (in the order passed to this constructor).


 Output<String> who = new PropertyOutput<>(field, "value", String.class);
 new JsAction("alert('Hello ' + output(0));", who);
 
See Also:
  • Field Details

  • Constructor Details

    • JsAction

      public JsAction(String expression, Output<?>... outputs)
      Creates a JS-backed action.
      Parameters:
      expression - the JS source, not null
      outputs - outputs available to the expression via output(i), in the order passed
  • Method Details

    • getExpression

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

      public List<Output<?>> getOutputs()
      Returns:
      the declared outputs in order
    • buildClientConfig

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

      Subclasses encode output references by calling ConfigContext.registerOutput(Output) and element references by calling ConfigContext.referenceElement(com.vaadin.flow.dom.Element). Public so the internal framework can read the config without reflection; subclasses just override.

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