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
GenericHasValueto 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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
-
-
Constructor Summary
Constructors Constructor Description ReadOnlyHasValue(SerializableConsumer<V> valueProcessor)Creates newReadOnlyHasValuewithnullas an empty value.ReadOnlyHasValue(SerializableConsumer<V> valueProcessor, V emptyValue)Creates newReadOnlyHasValue
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationaddValueChangeListener(HasValue.ValueChangeListener<? super HasValue.ValueChangeEvent<V>> listener)Adds a value change listener.VgetEmptyValue()Returns the value that represents an empty value.VgetValue()Returns the current value of this object.booleanisReadOnly()Returns whether thisHasValueis in read-only mode or not.booleanisRequiredIndicatorVisible()Checks whether the required indicator is visible.voidsetReadOnly(boolean readOnly)Sets the read-only mode of thisHasValueto given mode.voidsetRequiredIndicatorVisible(boolean requiredIndicatorVisible)Sets the required indicator visible or not.voidsetValue(V value)Sets the value of this object.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValue, isEmpty
-
-
-
-
Constructor Detail
-
ReadOnlyHasValue
public ReadOnlyHasValue(SerializableConsumer<V> valueProcessor, V emptyValue)
Creates newReadOnlyHasValue- Parameters:
valueProcessor- the value valueProcessor, e.g. a setter for displaying the value in a componentemptyValue- the value to be used as empty,nullby default
-
ReadOnlyHasValue
public ReadOnlyHasValue(SerializableConsumer<V> valueProcessor)
Creates newReadOnlyHasValuewithnullas an empty value.- Parameters:
valueProcessor- the value valueProcessor, e.g. a setter for displaying the value in a component
-
-
Method Detail
-
setValue
public void setValue(V value)
Description copied from interface:HasValueSets the value of this object. If the new value is not equal togetValue(), fires a value change event. May throwIllegalArgumentExceptionif 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 notnull.- Specified by:
setValuein interfaceHasValue<HasValue.ValueChangeEvent<V>,V>- Parameters:
value- the new value
-
getValue
public V getValue()
Description copied from interface:HasValueReturns 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 notnull.- Specified by:
getValuein interfaceHasValue<HasValue.ValueChangeEvent<V>,V>- Returns:
- the current value
-
addValueChangeListener
public Registration addValueChangeListener(HasValue.ValueChangeListener<? super HasValue.ValueChangeEvent<V>> listener)
Description copied from interface:HasValueAdds a value change listener. The listener is called when the value of thisHasValueis changed either by the user or programmatically.- Specified by:
addValueChangeListenerin interfaceHasValue<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:HasValueChecks whether the required indicator is visible.- Specified by:
isRequiredIndicatorVisiblein interfaceHasValue<HasValue.ValueChangeEvent<V>,V>- Returns:
trueif visible,falseif not
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Description copied from interface:HasValueSets 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
Binderwhich does server-side validation. In case HTML element has its own (client-side) validation it should be disabled whensetRequiredIndicatorVisible(true)is called and re-enabled back onsetRequiredIndicatorVisible(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 ownsetRequiredmethod which should be called in case the client-side validation is required.- Specified by:
setRequiredIndicatorVisiblein interfaceHasValue<HasValue.ValueChangeEvent<V>,V>- Parameters:
requiredIndicatorVisible-trueto make the required indicator visible,falseif not
-
setReadOnly
public void setReadOnly(boolean readOnly)
Description copied from interface:HasValueSets the read-only mode of thisHasValueto given mode. The user can't change the value when in read-only mode.A
HasValuewith a visual component in read-only mode typically looks visually different to signal to the user that the value cannot be edited.- Specified by:
setReadOnlyin interfaceHasValue<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:HasValueReturns whether thisHasValueis in read-only mode or not.- Specified by:
isReadOnlyin interfaceHasValue<HasValue.ValueChangeEvent<V>,V>- Returns:
falseif the user can modify the value,trueif not.
-
getEmptyValue
public V getEmptyValue()
Description copied from interface:HasValueReturns the value that represents an empty value.By default
HasValueis expected to supportnullas empty values. Specific implementations might not support this.- Specified by:
getEmptyValuein interfaceHasValue<HasValue.ValueChangeEvent<V>,V>- Returns:
- empty value
-
-