Class ExecutedJavaScript.Execution

java.lang.Object
com.vaadin.browserless.ExecutedJavaScript.Execution
All Implemented Interfaces:
Serializable
Enclosing class:
ExecutedJavaScript

public static final class ExecutedJavaScript.Execution extends Object implements Serializable
One piece of JavaScript sent to the browser.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    com.vaadin.flow.dom.Element
    Gets the element the JavaScript was run on, which is the element of the UI for JavaScript run on the page.
    Gets the JavaScript expression of this execution, in the form Flow sends it.
    Optional<com.vaadin.flow.js.JsCall>
    Gets the call of a JavaScript definition that this is, which says which definition, which method of it and with which arguments, as the application wrote it.
    Gets the parameters that the expression of this execution runs with, in the form Flow sends them.
    com.vaadin.flow.component.UI
    Gets the UI whose browser the JavaScript was sent to.
    void
    invokeReturnChannel(@Nullable Object... arguments)
    Calls the return channel passed to this JavaScript with the given arguments, as the JavaScript would call it in the browser.
    void
    invokeReturnChannelAt(int parameterIndex, @Nullable Object... arguments)
    Calls the return channel passed to this JavaScript as the parameter with the given index, as the JavaScript would call it in the browser, with a round trip before and after the call like invokeReturnChannel(Object...).
    boolean
    Checks whether the application waits for the result of this JavaScript, with PendingJavaScriptResult.then(java.lang.Class<T>, com.vaadin.flow.function.SerializableConsumer<T>, com.vaadin.flow.function.SerializableConsumer<java.lang.String>) or PendingJavaScriptResult.toCompletableFuture(java.lang.Class<T>), and it has not been answered yet, so that resolve(Object) and reject(String) can be called.
    void
    reject(String message)
    Answers the JavaScript with an error, as the browser does when the JavaScript throws, which runs the error handler the application registered.
    void
    resolve(@Nullable Object value)
    Answers the JavaScript with the given return value, as the browser does when the JavaScript has run, which runs the success handler the application registered.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • getUI

      public com.vaadin.flow.component.UI getUI()
      Gets the UI whose browser the JavaScript was sent to. A handler can use it to tell windows apart or to look at the state of the application in that window.
      Returns:
      the UI, not null
    • getElement

      public com.vaadin.flow.dom.Element getElement()
      Gets the element the JavaScript was run on, which is the element of the UI for JavaScript run on the page.
      Returns:
      the element, not null
    • getJsCall

      public Optional<com.vaadin.flow.js.JsCall> getJsCall()
      Gets the call of a JavaScript definition that this is, which says which definition, which method of it and with which arguments, as the application wrote it.
      Returns:
      the call, or empty for JavaScript run from a string with executeJs(String, Object...)
    • getExpression

      public String getExpression()
      Gets the JavaScript expression of this execution, in the form Flow sends it.
      • For a string run on the page with Page.executeJs(String, Object...), it is the expression as the application wrote it.
      • For a string run on an element with Element.executeJs(String, Object...), the expression the application wrote is wrapped so that it runs with the element as this; check it with contains(...).
      • For a call of a JavaScript definition, it is the declared expression of the called method, which the browser itself does not need; getJsCall() tells what was called.
      Returns:
      the expression, not null
    • getParameters

      public List<Object> getParameters()
      Gets the parameters that the expression of this execution runs with, in the form Flow sends them.
      • For a string run on the page, they are the parameters the application passed.
      • For a string run on an element, they are the parameters the application passed, followed by the element, which the expression uses as this.
      • For a call of a JavaScript definition, they are the arguments of the call, flattened, followed by the element, or null for a call on the page; getJsCall() gives the arguments as the application passed them.
      Returns:
      the parameters, not null
      See Also:
    • isWaitingForResult

      public boolean isWaitingForResult()
      Checks whether the application waits for the result of this JavaScript, with PendingJavaScriptResult.then(java.lang.Class<T>, com.vaadin.flow.function.SerializableConsumer<T>, com.vaadin.flow.function.SerializableConsumer<java.lang.String>) or PendingJavaScriptResult.toCompletableFuture(java.lang.Class<T>), and it has not been answered yet, so that resolve(Object) and reject(String) can be called.
      Returns:
      true if the application waits for a result that has not been given yet
    • resolve

      public void resolve(@Nullable Object value)
      Answers the JavaScript with the given return value, as the browser does when the JavaScript has run, which runs the success handler the application registered.
      Parameters:
      value - the value the JavaScript returned, converted to JSON the way Flow converts a value; a JsonNode is used as is
      Throws:
      IllegalStateException - if the application does not wait for the result, or if the JavaScript was already answered
    • reject

      public void reject(String message)
      Answers the JavaScript with an error, as the browser does when the JavaScript throws, which runs the error handler the application registered.
      Parameters:
      message - the error message, not null
      Throws:
      IllegalStateException - if the application does not wait for the result, or if the JavaScript was already answered
    • invokeReturnChannel

      public void invokeReturnChannel(@Nullable Object... arguments)
      Calls the return channel passed to this JavaScript with the given arguments, as the JavaScript would call it in the browser. A round trip runs before the call, as the browser acts on the latest response, and after it, so that JavaScript the channel's handler schedules is sent.

      A JavaScriptHandler can call this method too, for a channel the browser calls as soon as the JavaScript runs. JavaScript the channel's handler schedules is then sent at the next client boundary.

      The UI the JavaScript was sent to must be the current UI, as the channel's handler runs in it: with several windows, activate its window first.

      The JavaScript must have received exactly one ReturnChannelRegistration among its parameters; use invokeReturnChannelAt(int, Object...) to pick one of several.

      The same checks apply as when Flow receives a return channel message from the browser, but where Flow ignores the message, this method throws: the channel must still be registered, and its element must be attached and visible, and enabled unless the channel's DisabledUpdateMode is ALWAYS.

      Parameters:
      arguments - the arguments the JavaScript passes to the channel, each converted to JSON the way Flow converts a value; a JsonNode is used as is
      Throws:
      IllegalStateException - if the JavaScript received no return channel or more than one, if the UI the JavaScript was sent to is not the current UI, or if Flow would ignore the message
      See Also:
    • invokeReturnChannelAt

      public void invokeReturnChannelAt(int parameterIndex, @Nullable Object... arguments)
      Calls the return channel passed to this JavaScript as the parameter with the given index, as the JavaScript would call it in the browser, with a round trip before and after the call like invokeReturnChannel(Object...).

      Unlike invokeReturnChannel(Object...), this method works when the JavaScript received several return channels. The same checks apply as when Flow receives a return channel message from the browser, but where Flow ignores the message, this method throws.

      Parameters:
      parameterIndex - the index of the channel in getParameters()
      arguments - the arguments the JavaScript passes to the channel, each converted to JSON the way Flow converts a value; a JsonNode is used as is
      Throws:
      IllegalArgumentException - if there is no parameter with the given index, or it is not a ReturnChannelRegistration
      IllegalStateException - if the UI the JavaScript was sent to is not the current UI, or if Flow would ignore the message
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object