Class SignalBinding<T extends @Nullable Object>

java.lang.Object
com.vaadin.flow.dom.SignalBinding<T>
Type Parameters:
T - the type of the bound signal value
All Implemented Interfaces:
Serializable

public class SignalBinding<T extends @Nullable Object> extends Object implements Serializable
Represents an active binding between a signal and an element property (text, attribute, visibility, etc.). Provides the ability to register callbacks that are invoked whenever the binding updates, with rich context about the update.

Typical usage:

 span.bindText(signal).onChange(ctx -> {
     if (ctx.isBackgroundChange()) {
         ctx.getElement().flashClass("highlight");
     }
 });
 
See Also:
  • Constructor Details

    • SignalBinding

      public SignalBinding()
      Creates a new signal binding.

      For internal use only. May be renamed or removed in a future release.

  • Method Details

    • onChange

      public SignalBinding<T> onChange(SerializableConsumer<BindingContext<T>> action)
      Registers a callback that is invoked every time the bound signal value changes and the binding updates the element. The callback receives a BindingContext that provides the old value, new value, target element, nearest component, and whether the change was a background update, initial render, or user-triggered.

      Multiple callbacks can be registered by calling this method multiple times. All registered callbacks are invoked in registration order.

      Example:

       span.bindText(signal).onChange(ctx -> {
           if (ctx.isBackgroundChange()) {
               ctx.getElement().flashClass("highlight");
           }
       });
       
      Parameters:
      action - the callback to invoke on each update, not null
      Returns:
      this binding for fluent chaining
    • hasCallbacks

      public boolean hasCallbacks()
      Returns whether any onChange callbacks have been registered.

      For internal use only. May be renamed or removed in a future release.

      Returns:
      true if there are callbacks, false otherwise
    • fireOnChange

      public void fireOnChange(BindingContext<T> context)
      Fires all registered onChange callbacks with the given context. Called internally by the binding effect after the setter has been applied.

      For internal use only. May be renamed or removed in a future release.

      Parameters:
      context - the binding context for this execution