Annotation Interface JsExpression


@Documented @Target(METHOD) @Retention(RUNTIME) public @interface JsExpression
The JavaScript that a method of a JavaScript definition runs, as a constant expression.

The annotated method is called through Element.executeJs(Class). Its arguments are the parameters of the expression, referenced positionally as $0, $1, …, and the element the definition was obtained from is this — the same contract as Element.executeJs(String, Object...), except that the expression is a constant of the interface instead of a string built at the call site.

A method that returns a JsSnippet is called through JsSnippets.of(Class) instead, and runs nothing when it is called. Its arguments are still $0, $1, …, but the expression is evaluated later by what the snippet is passed to, and this is whatever that invoker supplies. See JsFunctionParameterNames for the parameters it is called with.

A method of an interface that extends JsInvokers can leave the annotation out to call the method of the same name on this, with the arguments of the call, and answer with what it returns. The two methods below declare the same JavaScript:

 @JsExpression("return this.showPopover($0);")
 void showPopover(JsonNode options);

 void showPopover(JsonNode options);
 
The last argument of a variadic method is spread into the call. What counts is the interface that declares the method: a method that a definition inherits from an interface that does not extend JsInvokers, and a method of a JsSnippets interface, need the annotation. So does a method of an interface annotated with JsStringFallback, which is matched by the JavaScript it declares, and a method called through Page.executeJs(Class), which runs on no element.
Since:
25.4
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The JavaScript expression to run.
  • Element Details

    • value

      String value
      The JavaScript expression to run.
      Returns:
      the expression