Class AbstractFieldSupport<C extends Component & HasValue<AbstractField.ComponentValueChangeEvent<C,T>,T>,T>

java.lang.Object
com.vaadin.flow.component.internal.AbstractFieldSupport<C,T>
Type Parameters:
C - the value change source type
T - the value type
All Implemented Interfaces:
Serializable

public class AbstractFieldSupport<C extends Component & HasValue<AbstractField.ComponentValueChangeEvent<C,T>,T>,T> extends Object implements Serializable
Encapsulates all the logic required for a typical field implementation. This reduces the risk of implementing logic changes in AbstractField but not in AbstractCompositeField, or vice versa.

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

Since:
1.0
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • AbstractFieldSupport

      public AbstractFieldSupport(C component, T defaultValue, SerializableBiPredicate<T,T> valueEquals, SerializableConsumer<T> setPresentationValue)
      Creates a new field support.
      Parameters:
      component - the owning field component
      defaultValue - the default field value
      valueEquals - a callback for comparing values
      setPresentationValue - a callback for setting presentation values
  • Method Details

    • addValueChangeListener

      public Registration addValueChangeListener(HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<C,T>> listener)
      Parameters:
      listener - the listener to add
      Returns:
      a registration for the listener
    • getValue

      public T getValue()
      Delegate method for HasValue.getValue().
      Returns:
      the field value
    • getEmptyValue

      public T getEmptyValue()
      Delegate method for HasValue.getEmptyValue().
      Returns:
      the empty value of this field
    • setValue

      public void setValue(T value)
      Delegate method for HasValue.setValue(Object).
      Parameters:
      value - the value to set
    • valueEquals

      public boolean valueEquals(T value1, T value2)
      Delegate method corresponding to AbstractField.valueEquals(Object, Object).
      Parameters:
      value1 - the first instance
      value2 - the second instance
      Returns:
      true if the instances are equal; otherwise false
    • setModelValue

      public void setModelValue(T newModelValue, boolean fromClient)
      Delegate method corresponding to AbstractField.setModelValue(Object, boolean).
      Parameters:
      newModelValue - the new internal value to use
      fromClient - true if the new value originates from the client; otherwise false
    • bindValue

      public void bindValue(Signal<T> valueSignal, SerializableConsumer<T> writeCallback)
      Binds a Signal's value to the value state of the field and keeps the state synchronized with the signal value while the element is in attached state. When the element is in detached state, signal value changes have no effect.

      While a Signal is bound to a value state, any attempt to bind a new Signal while one is already bound throws BindingActiveException.

      While a Signal is bound to a value state and the element is in attached state, setting the value with setValue(Object), setModelValue(Object, boolean), or when a change originates from the client, will invoke the write callback to propagate the value back. After the callback, the signal is re-consulted and if its value differs from what was being set, the new value is ignored and the signal's updated value is used instead, i.e. in cases where write callback has `signal.set("different")`, whereas a value being set is "a new value", the "different" value wins.

      If the write callback is null, the binding is read-only and any attempt to set the value while attached will throw an IllegalStateException.

      Parameters:
      valueSignal - the signal to bind, not null
      writeCallback - the callback to propagate value changes back, or null for a read-only binding
      Throws:
      BindingActiveException - thrown when there is already an existing binding
      See Also: