Package com.vaadin.data
Class ReadOnlyHasValue<V>
- java.lang.Object
-
- com.vaadin.data.ReadOnlyHasValue<V>
-
- Type Parameters:
V
- the value type
- All Implemented Interfaces:
HasValue<V>
,Serializable
public class ReadOnlyHasValue<V> extends Object implements HasValue<V>, Serializable
GenericHasValue
to use any type of component with Vaadin data binding.Example:
Label label = new Label(); ReadOnlyHasValue<String> hasValue = new ReadOnlyHasValue<>( label::setCaption); binder.forField(hasValue).bind(SomeBean::getName);
- Since:
- 8.4
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.vaadin.data.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
-
-
Constructor Summary
Constructors Constructor Description ReadOnlyHasValue(SerializableConsumer<V> valueProcessor)
Creates newReadOnlyHasValue
withnull
as an empty value.ReadOnlyHasValue(SerializableConsumer<V> valueProcessor, V emptyValue)
Creates newReadOnlyHasValue
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Registration
addValueChangeListener(HasValue.ValueChangeListener<V> listener)
Adds a value change listener.V
getEmptyValue()
Returns the value that represents an empty value.V
getValue()
Returns the current value of this object.boolean
isReadOnly()
Returns whether thisHasValue
is in read-only mode or not.boolean
isRequiredIndicatorVisible()
Checks whether the required indicator is visible.void
setReadOnly(boolean readOnly)
Sets the read-only mode of thisHasValue
to given mode.void
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets the required indicator visible or not.void
setValue(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.data.HasValue
clear, getDefaultValidator, getOptionalValue, isEmpty
-
-
-
-
Constructor Detail
-
ReadOnlyHasValue
public ReadOnlyHasValue(SerializableConsumer<V> valueProcessor, V emptyValue)
Creates newReadOnlyHasValue
.- Parameters:
valueProcessor
- the value valueProcessor, e.g.Label.setValue(java.lang.String)
emptyValue
- the value to be used as empty,null
by default
-
ReadOnlyHasValue
public ReadOnlyHasValue(SerializableConsumer<V> valueProcessor)
Creates newReadOnlyHasValue
withnull
as an empty value.- Parameters:
valueProcessor
- the value valueProcessor, e.g.Label.setValue(java.lang.String)
-
-
Method Detail
-
setValue
public void setValue(V value)
Description copied from interface:HasValue
Sets the value of this object. If the new value is not equal togetValue()
, fires a value change event. May throwIllegalArgumentException
if the value is not acceptable.Implementation note: the implementing class should document whether null values are accepted or not.
-
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.
-
addValueChangeListener
public Registration addValueChangeListener(HasValue.ValueChangeListener<V> listener)
Description copied from interface:HasValue
Adds a value change listener. The listener is called when the value of thisHasValue
is changed either by the user or programmatically.- Specified by:
addValueChangeListener
in interfaceHasValue<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 interfaceHasValue<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.
- Specified by:
setRequiredIndicatorVisible
in interfaceHasValue<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 thisHasValue
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 interfaceHasValue<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 thisHasValue
is in read-only mode or not.- Specified by:
isReadOnly
in interfaceHasValue<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 supportnull
as empty values. Specific implementations might not support this.- Specified by:
getEmptyValue
in interfaceHasValue<V>
- Returns:
- empty value
- See Also:
Binder#bind(HasValue, ValueProvider, Setter)
-
-