Class JsOutput<T>

java.lang.Object
com.vaadin.flow.component.trigger.AbstractOutput<T>
com.vaadin.flow.component.trigger.JsOutput<T>
Type Parameters:
T - the runtime type of the produced value
All Implemented Interfaces:
Output<T>, Serializable

public class JsOutput<T> extends AbstractOutput<T>
Output backed by an arbitrary JavaScript expression — the escape hatch for cases not covered by a built-in AbstractOutput.

The expression runs at the moment the trigger fires and its return value becomes the output. The expression executes in the global scope; use document.querySelector(...) or other DOM globals to reach elements.


 Output<String> hostName = new JsOutput<>(String.class,
         "return window.location.hostname;");
 
See Also:
  • Field Details

  • Constructor Details

    • JsOutput

      public JsOutput(Class<T> valueType, String expression)
      Creates a JS-backed output.
      Parameters:
      valueType - the runtime type, 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: AbstractOutput
      Produces the JSON configuration this output sends to the client. Default is an empty object; override to add type-specific options.

      Subclasses encode 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 AbstractOutput<T>
      Parameters:
      context - the resolver for referenced elements, not null
      Returns:
      a Jackson ObjectNode, never null