Class SetPropertyTemporarilyAction<T>
- Type Parameters:
T- the runtime type of the value to assign
- All Implemented Interfaces:
Serializable
The "previous" value is read on the client at the first fire of a cycle, before the new value is assigned. Rapid re-fires within the timeout window are coalesced: the original captured on the first fire is preserved, the new value is applied again, and the revert timer is reset. This means a second click on a flashing button extends the flash by one timeout, rather than capturing the already-flashed value as "original". Coalescing is keyed per element and per property name, so unrelated temporary modifications on the same element do not interfere.
The default timeout is 1000L ms
(DEFAULT_TIMEOUT). Passing Duration.ZERO is allowed and
queues the reversion onto the next event-loop turn — the new value is briefly
visible before reverting, which is a legitimate "flash" / "pulse" pattern.
Symmetric with SetPropertyAction, which applies the value
permanently. The value to assign can be either a literal (constant,
serialised at build time) or an Action.Input that produces the value
on the client when the trigger fires.
Common idioms:
- Flash a button into a "copied" state for one second:
new SetPropertyTemporarilyAction(button, "innerText", "Copied!") - Mark an input invalid for half a second:
new SetPropertyTemporarilyAction(input, "invalid", true, Duration.ofMillis(500))
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> -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSetPropertyTemporarilyAction(Component target, String propertyName, @Nullable T value) Creates an action that temporarily assigns the given literal value to the given JS property ontargetwhen the trigger fires, reverting afterDEFAULT_TIMEOUT.SetPropertyTemporarilyAction(Component target, String propertyName, @Nullable T value, Duration timeout) Creates an action that temporarily assigns the given literal value to the given JS property ontargetwhen the trigger fires, reverting aftertimeout.SetPropertyTemporarilyAction(Component target, String propertyName, Action.Input<? extends T> source) Creates an action that temporarily assigns the value produced bysourceto the given JS property ontargetwhen the trigger fires, reverting afterDEFAULT_TIMEOUT.SetPropertyTemporarilyAction(Component target, String propertyName, Action.Input<? extends T> source, Duration timeout) Creates an action that temporarily assigns the value produced bysourceto the given JS property ontargetwhen the trigger fires, reverting aftertimeout. -
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
-
Field Details
-
DEFAULT_TIMEOUT
Default timeout used by constructors that don't take an explicitDuration: one second.
-
-
Constructor Details
-
SetPropertyTemporarilyAction
Creates an action that temporarily assigns the given literal value to the given JS property ontargetwhen the trigger fires, reverting afterDEFAULT_TIMEOUT.- Parameters:
target- the component whose root element to modify, notnullpropertyName- the JS property name, notnullvalue- the value to assign temporarily —String,Boolean,Number, or any Jackson-serialisable object; may benullto emit a JSnull
-
SetPropertyTemporarilyAction
public SetPropertyTemporarilyAction(Component target, String propertyName, @Nullable T value, Duration timeout) Creates an action that temporarily assigns the given literal value to the given JS property ontargetwhen the trigger fires, reverting aftertimeout.- Parameters:
target- the component whose root element to modify, notnullpropertyName- the JS property name, notnullvalue- the value to assign temporarily —String,Boolean,Number, or any Jackson-serialisable object; may benullto emit a JSnulltimeout- how long to keep the value before reverting, notnulland not negative;Duration.ZEROis allowed
-
SetPropertyTemporarilyAction
public SetPropertyTemporarilyAction(Component target, String propertyName, Action.Input<? extends T> source) Creates an action that temporarily assigns the value produced bysourceto the given JS property ontargetwhen the trigger fires, reverting afterDEFAULT_TIMEOUT.- Parameters:
target- the component whose root element to modify, notnullpropertyName- the JS property name, notnullsource- input that produces the value to assign, notnull
-
SetPropertyTemporarilyAction
public SetPropertyTemporarilyAction(Component target, String propertyName, Action.Input<? extends T> source, Duration timeout) Creates an action that temporarily assigns the value produced bysourceto the given JS property ontargetwhen the trigger fires, reverting aftertimeout.- Parameters:
target- the component whose root element to modify, notnullpropertyName- the JS property name, notnullsource- input that produces the value to assign, notnulltimeout- how long to keep the value before reverting, notnulland not negative;Duration.ZEROis allowed
-
-
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).
-