Annotation Interface JsExpression
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
-
Element Details
-
value
String valueThe JavaScript expression to run.- Returns:
- the expression
-