Class PromiseAction
java.lang.Object
com.vaadin.flow.component.trigger.internal.Action
com.vaadin.flow.component.trigger.internal.PromiseAction
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
CopyTextToClipboardAction,RequestFullscreenAction
Base class for actions that run a JS expression yielding a Promise
and optionally report the outcome back to the server.
Many gesture-bound browser APIs are asynchronous — clipboard, fullscreen,
file picker, share, web payment, … — and follow the same shape: call the API,
then handle the resolved value or the rejection. This class collapses that
pattern into one place so subclasses only need to emit the promise-yielding
JS expression by overriding
appendPromiseExpression(JsBuilder, StringBuilder).
Two construction modes, mirroring the
Geolocation API:
- Fire-and-forget —
PromiseAction()— the rendered JS is just the promise expression; the server never sees the outcome. - With outcome handling —
PromiseAction(SerializableRunnable, SerializableConsumer)— supply anonSuccessrunnable and anonErrorconsumer (both required; pass() -> {}orerr -> {}to opt out of one). The handlers run on the UI thread after the client reports the outcome of the promise.
JsFunction that subscribes to the promise and pushes an
PromiseAction.Outcome record through a lazily-registered
ReturnChannelRegistration on the trigger host node.
For internal use only. May be renamed or removed in a future release.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.trigger.internal.Action
Action.Input<T> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a fire-and-forget action: the promise's outcome is not reported back to the server.protectedPromiseAction(SerializableRunnable onSuccess, SerializableConsumer<String> onError) Creates an action whose promise outcome is reported back to the server. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidappendPromiseExpression(com.vaadin.flow.component.trigger.internal.JsBuilder builder, StringBuilder out) Subclasses append a JS expression that evaluates to aPromisewhen the trigger fires.protected final voidappendStatement(com.vaadin.flow.component.trigger.internal.JsBuilder builder, StringBuilder out) Appends this action's JS statement toout.
-
Constructor Details
-
PromiseAction
protected PromiseAction()Creates a fire-and-forget action: the promise's outcome is not reported back to the server. -
PromiseAction
Creates an action whose promise outcome is reported back to the server.onSuccessruns after the promise resolves;onErrorreceives the browser's error message after the promise rejects. Both run on the UI thread. Both consumers are required and must be non-null — pass() -> {}orerr -> {}to opt out of one.- Parameters:
onSuccess- invoked on the UI thread after the client reports the promise resolved, notnullonError- invoked on the UI thread with the browser's error message after the client reports the promise rejected, notnull
-
-
Method Details
-
appendPromiseExpression
protected abstract void appendPromiseExpression(com.vaadin.flow.component.trigger.internal.JsBuilder builder, StringBuilder out) Subclasses append a JS expression that evaluates to aPromisewhen the trigger fires. The result of that promise is whatonSuccess/onErrorobserve; the resolved value itself is not delivered to the server (only success vs. failure and the rejection message).- Parameters:
builder- collects element parameter references, notnullout- buffer to append into, notnull
-
appendStatement
protected final void appendStatement(com.vaadin.flow.component.trigger.internal.JsBuilder builder, StringBuilder out) Description copied from class:ActionAppends this action's JS statement toout. Element references must go throughJsBuilder.reference(com.vaadin.flow.dom.Element).- Specified by:
appendStatementin classAction- Parameters:
builder- collects element parameter references, notnullout- buffer to append into, notnull
-