Class ExecutedJavaScript.Execution
- All Implemented Interfaces:
Serializable
- Enclosing class:
ExecutedJavaScript
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.dom.ElementGets 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.UIgetUI()Gets the UI whose browser the JavaScript was sent to.voidinvokeReturnChannel(@Nullable Object... arguments) Calls the return channel passed to this JavaScript with the given arguments, as the JavaScript would call it in the browser.voidinvokeReturnChannelAt(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 likeinvokeReturnChannel(Object...).booleanChecks whether the application waits for the result of this JavaScript, withPendingJavaScriptResult.then(java.lang.Class<T>, com.vaadin.flow.function.SerializableConsumer<T>, com.vaadin.flow.function.SerializableConsumer<java.lang.String>)orPendingJavaScriptResult.toCompletableFuture(java.lang.Class<T>), and it has not been answered yet, so thatresolve(Object)andreject(String)can be called.voidAnswers the JavaScript with an error, as the browser does when the JavaScript throws, which runs the error handler the application registered.voidAnswers the JavaScript with the given return value, as the browser does when the JavaScript has run, which runs the success handler the application registered.toString()
-
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
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
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 asthis; check it withcontains(...). - 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
- For a string run on the page with
-
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
nullfor 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, withPendingJavaScriptResult.then(java.lang.Class<T>, com.vaadin.flow.function.SerializableConsumer<T>, com.vaadin.flow.function.SerializableConsumer<java.lang.String>)orPendingJavaScriptResult.toCompletableFuture(java.lang.Class<T>), and it has not been answered yet, so thatresolve(Object)andreject(String)can be called.- Returns:
- true if the application waits for a result that has not been given yet
-
resolve
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; aJsonNodeis used as is- Throws:
IllegalStateException- if the application does not wait for the result, or if the JavaScript was already answered
-
reject
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
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
JavaScriptHandlercan 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
ReturnChannelRegistrationamong its parameters; useinvokeReturnChannelAt(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
DisabledUpdateModeisALWAYS.- Parameters:
arguments- the arguments the JavaScript passes to the channel, each converted to JSON the way Flow converts a value; aJsonNodeis 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
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 likeinvokeReturnChannel(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 ingetParameters()arguments- the arguments the JavaScript passes to the channel, each converted to JSON the way Flow converts a value; aJsonNodeis used as is- Throws:
IllegalArgumentException- if there is no parameter with the given index, or it is not aReturnChannelRegistrationIllegalStateException- if the UI the JavaScript was sent to is not the current UI, or if Flow would ignore the message- See Also:
-
toString
-