Class ReadOnlyHasValue<V>

java.lang.Object
com.vaadin.flow.data.binder.ReadOnlyHasValue<V>
Type Parameters:
V - the value type
All Implemented Interfaces:
HasValue<HasValue.ValueChangeEvent<V>,V>, Serializable

public class ReadOnlyHasValue<V> extends Object implements HasValue<HasValue.ValueChangeEvent<V>,V>, Serializable
Generic HasValue to use any type of component with Vaadin data binding.

Example:

 Label label = new Label();
 ReadOnlyHasValue<String> hasValue = new ReadOnlyHasValue<>(label::setText);
 binder.forField(hasValue).bind(SomeBean::getName, null);
 
Since:
1.0
See Also:
  • Constructor Details

    • ReadOnlyHasValue

      public ReadOnlyHasValue(SerializableConsumer<V> valueProcessor, V emptyValue)
      Creates new ReadOnlyHasValue
      Parameters:
      valueProcessor - the value valueProcessor, e.g. a setter for displaying the value in a component
      emptyValue - the value to be used as empty, null by default
    • ReadOnlyHasValue

      public ReadOnlyHasValue(SerializableConsumer<V> valueProcessor)
      Creates new ReadOnlyHasValue with null as an empty value.
      Parameters:
      valueProcessor - the value valueProcessor, e.g. a setter for displaying the value in a component
  • Method Details

    • setValue

      public void setValue(V value)
      Description copied from interface: HasValue
      Sets the value of this object. If the new value is not equal to getValue(), fires a value change event. May throw IllegalArgumentException if the value is not acceptable.

      Implementation note: the implementing class should document whether null values are accepted or not, and override HasValue.getEmptyValue() if the empty value is not null.

      Specified by:
      setValue in interface HasValue<HasValue.ValueChangeEvent<V>,V>
      Parameters:
      value - the new value
    • getValue

      public V getValue()
      Description copied from interface: HasValue
      Returns the current value of this object.

      Implementation note: the implementing class should document whether null values may be returned or not, and override HasValue.getEmptyValue() if the empty value is not null.

      Specified by:
      getValue in interface HasValue<HasValue.ValueChangeEvent<V>,V>
      Returns:
      the current value
    • addValueChangeListener

      public Registration addValueChangeListener(HasValue.ValueChangeListener<? super HasValue.ValueChangeEvent<V>> listener)
      Description copied from interface: HasValue
      Adds a value change listener. The listener is called when the value of this HasValue is changed either by the user or programmatically.
      Specified by:
      addValueChangeListener in interface HasValue<HasValue.ValueChangeEvent<V>,V>
      Parameters:
      listener - the value change listener, not null
      Returns:
      a registration for the listener
    • isRequiredIndicatorVisible

      public boolean isRequiredIndicatorVisible()
      Description copied from interface: HasValue
      Checks whether the required indicator is visible.
      Specified by:
      isRequiredIndicatorVisible in interface HasValue<HasValue.ValueChangeEvent<V>,V>
      Returns:
      true if visible, false if not
    • setRequiredIndicatorVisible

      public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
      Description copied from interface: HasValue
      Sets the required indicator visible or not.

      If set visible, it is visually indicated in the user interface.

      The method is intended to be used with Binder which does server-side validation. In case HTML element has its own (client-side) validation it should be disabled when setRequiredIndicatorVisible(true) is called and re-enabled back on setRequiredIndicatorVisible(false). It's responsibility of each component implementation to follow the contract so that the method call doesn't do anything else than show/hide the "required" indication. Usually components provide their own setRequired method which should be called in case the client-side validation is required.

      Specified by:
      setRequiredIndicatorVisible in interface HasValue<HasValue.ValueChangeEvent<V>,V>
      Parameters:
      requiredIndicatorVisible - true to make the required indicator visible, false if not
    • setReadOnly

      public void setReadOnly(boolean readOnly)
      Description copied from interface: HasValue
      Sets the read-only mode of this HasValue to given mode. The user can't change the value when in read-only mode.

      A HasValue with a visual component in read-only mode typically looks visually different to signal to the user that the value cannot be edited.

      Specified by:
      setReadOnly in interface HasValue<HasValue.ValueChangeEvent<V>,V>
      Parameters:
      readOnly - a boolean value specifying whether the component is put read-only mode or not
    • isReadOnly

      public boolean isReadOnly()
      Description copied from interface: HasValue
      Returns whether this HasValue is in read-only mode or not.
      Specified by:
      isReadOnly in interface HasValue<HasValue.ValueChangeEvent<V>,V>
      Returns:
      false if the user can modify the value, true if not.
    • getEmptyValue

      public V getEmptyValue()
      Description copied from interface: HasValue
      Returns the value that represents an empty value.

      By default HasValue is expected to support null as empty values. Specific implementations might not support this.

      Specified by:
      getEmptyValue in interface HasValue<HasValue.ValueChangeEvent<V>,V>
      Returns:
      empty value