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

public class BindingContext<T extends @Nullable Object> extends EffectContext
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 Details

    • BindingContext

      public BindingContext(boolean initialRun, T oldValue, T newValue, Element element)
      Creates a new binding context.
      Parameters:
      initialRun - whether this is the first execution of the binding effect
      oldValue - the previous value (same as newValue on initial run)
      newValue - the current value
      element - the target element of the binding
  • Method Details

    • getOldValue

      public T getOldValue()
      Returns the previous value before this update. On the initial run, this is the same as getNewValue().
      Returns:
      the old value
    • getNewValue

      public T getNewValue()
      Returns the current value after this update.
      Returns:
      the new value
    • getElement

      public Element getElement()
      Returns the target element that the signal is bound to.
      Returns:
      the target element, not null
    • getComponent

      public @Nullable Component 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 null if no component is found in the element hierarchy