Class CallbackAction<T>
- Type Parameters:
T- the type the JSON value is decoded to and the callback receives
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SetSignalAction
SerializableConsumer on the UI thread. The generic
counterpart to client-side actions like SetPropertyAction — same
input/source story, except the destination is a Java callback instead of a JS
assignment.
Use this as the bridge from a trigger to arbitrary server-side state — log a
value, fire a custom event, push to a queue, etc. The SetSignalAction
subclass is the named convenience for the common case of forwarding into a
ValueSignal.
Example — log the screen-X coordinate of each click:
ClickTrigger click = new ClickTrigger(button);
click.triggers(new CallbackAction<>(Integer.class,
x -> logger.info("clicked at {}", x), click.screenX()));
The rendered JS calls a ReturnChannelRegistration that, on the
server, decodes the JSON value as T and invokes the callback. A null
value on the wire (a JSON null or a missing argument) is rejected
with IllegalStateException — callbacks see decoded, non-null values
only. A separate channel is registered per host node, so the same action
instance can be wired to triggers hosted on different elements without
leaking registrations across them.
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
ConstructorsConstructorDescriptionCallbackAction(Class<T> valueType, SerializableConsumer<T> callback, Action.Input<? extends T> source) Creates an action that, when the trigger fires, evaluatessourceon the client, sends the value to the server, decodes it asvalueType, and hands it tocallbackon the UI thread. -
Method Summary
Modifier and TypeMethodDescriptionprotected final JsFunctionBuilds theJsFunctionthat runs this action when the surrounding trigger fires.Methods inherited from class com.vaadin.flow.component.trigger.internal.Action
warnIfNotVisible
-
Constructor Details
-
CallbackAction
public CallbackAction(Class<T> valueType, SerializableConsumer<T> callback, Action.Input<? extends T> source) Creates an action that, when the trigger fires, evaluatessourceon the client, sends the value to the server, decodes it asvalueType, and hands it tocallbackon the UI thread.- Parameters:
valueType- runtime type the JSON value is decoded to before being passed tocallback, notnullcallback- invoked on the UI thread with the decoded value, notnullsource- input that produces the value on the client when the trigger fires, notnull
-
-
Method Details
-
toJs
Description copied from class:ActionBuilds theJsFunctionthat runs this action when the surrounding trigger fires. The returned function takes one runtime argument namedevent(declared by the framework when it composes the trigger handler); subclasses do not declare argument names themselves.The body is one statement. To embed a value produced on the client, capture an
Action.Input'sJsFunctionas a capture and invoke it inside the body as$N(event).
-