Package com.vaadin.flow.dom
Class BindingContext<T extends @Nullable Object>
java.lang.Object
com.vaadin.flow.signals.EffectContext
com.vaadin.flow.dom.BindingContext<T>
- Type Parameters:
T- the type of the bound signal value
- All Implemented Interfaces:
Serializable
Provides rich context information about a signal binding update. Extends
EffectContext with binding-specific information such as old and new
values, target element, and nearest component.
Typical usage:
span.bindText(signal).onChange(ctx -> {
if (ctx.isBackgroundChange()) {
ctx.getElement().flashClass("highlight");
}
});
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionBindingContext(boolean initialRun, T oldValue, T newValue, Element element) Creates a new binding context. -
Method Summary
Modifier and TypeMethodDescription@Nullable ComponentReturns the nearest component for the target element.Returns the target element that the signal is bound to.Returns the current value after this update.Returns the previous value before this update.Methods inherited from class com.vaadin.flow.signals.EffectContext
isBackgroundChange, isInitialRun
-
Constructor Details
-
BindingContext
Creates a new binding context.- Parameters:
initialRun- whether this is the first execution of the binding effectoldValue- the previous value (same as newValue on initial run)newValue- the current valueelement- the target element of the binding
-
-
Method Details
-
getOldValue
Returns the previous value before this update. On the initial run, this is the same asgetNewValue().- Returns:
- the old value
-
getNewValue
Returns the current value after this update.- Returns:
- the new value
-
getElement
Returns the target element that the signal is bound to.- Returns:
- the target element, not
null
-
getComponent
Returns the nearest component for the target element. If the element itself has an associated component, that component is returned. Otherwise, the element tree is traversed upward to find the first ancestor with an associated component.- Returns:
- the nearest component, or
nullif no component is found in the element hierarchy
-