Class CallMethodAction
- All Implemented Interfaces:
Serializable
Each argument is supplied as an Action.Input: a literal captured at
build time, the current value of a DOM property, an event-scoped expression,
or any other input. The rendered JS evaluates target[method](arg0,
arg1, ...) where each argN is the input's value at the moment the
trigger fires.
Common idioms:
- Focus an input on click:
new CallMethodAction(input, "focus") - Scroll an element into view:
new CallMethodAction(panel, "scrollIntoView") - Select all text:
new CallMethodAction(field, "select") - Click another element:
new CallMethodAction(other, "click") - Submit a form:
new CallMethodAction(form, "requestSubmit") - Play / pause a media element:
new CallMethodAction(video, "play")/new CallMethodAction(video, "pause") - Pass an options object built on the server:
new CallMethodAction(panel, "scrollIntoView", new LiteralInput<>(Map.of("behavior", "smooth")))
For methods that return a Promise, the promise is created and dropped
— the JS engine may log an unhandled-rejection warning if the promise
rejects. Use PromiseAction based actions when you need to observe the
outcome on the server.
Server-side state is not updated by this action; the call lives in the browser until the next sync from the client (if any).
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
ConstructorsConstructorDescriptionCallMethodAction(Component target, String methodName, Action.Input<?>... arguments) Creates an action that, when the trigger fires, evaluates each input on the client and callstarget[methodName](...)with those values. -
Method Summary
Modifier and TypeMethodDescriptionprotected JsFunctionBuilds theJsFunctionthat runs this action when the surrounding trigger fires.Methods inherited from class com.vaadin.flow.component.trigger.internal.Action
applyTemporarily, warnIfNotVisible
-
Constructor Details
-
CallMethodAction
Creates an action that, when the trigger fires, evaluates each input on the client and callstarget[methodName](...)with those values.- Parameters:
target- the component on whose root element the method is invoked, notnullmethodName- the JS method name (e.g."focus","scrollIntoView"), notnullarguments- inputs producing the method's positional arguments, in order; may be empty for a no-arg call. Neither the array nor any element may benull
-
-
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).
-