Class ReadOnlyHasValue<V>
- Type Parameters:
V
- the value type
- All Implemented Interfaces:
HasValue<HasValue.ValueChangeEvent<V>,
,V> Serializable
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:
-
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
ConstructorDescriptionReadOnlyHasValue
(SerializableConsumer<V> valueProcessor) Creates newReadOnlyHasValue
withnull
as an empty value.ReadOnlyHasValue
(SerializableConsumer<V> valueProcessor, V emptyValue) Creates newReadOnlyHasValue
-
Method Summary
Modifier and TypeMethodDescriptionaddValueChangeListener
(HasValue.ValueChangeListener<? super HasValue.ValueChangeEvent<V>> listener) Adds a value change listener.Returns the value that represents an empty value.getValue()
Returns the current value of this object.boolean
Returns whether thisHasValue
is in read-only mode or not.boolean
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
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 Details
-
ReadOnlyHasValue
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,null
by default
-
ReadOnlyHasValue
Creates newReadOnlyHasValue
withnull
as an empty value.- Parameters:
valueProcessor
- the value valueProcessor, e.g. a setter for displaying the value in a component
-
-
Method Details
-
setValue
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, and override
HasValue.getEmptyValue()
if the empty value is notnull
.- Specified by:
setValue
in interfaceHasValue<HasValue.ValueChangeEvent<V>,
V> - Parameters:
value
- the new value
-
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 notnull
.- Specified by:
getValue
in interfaceHasValue<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 thisHasValue
is changed either by the user or programmatically.- Specified by:
addValueChangeListener
in 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:HasValue
Checks whether the required indicator is visible.- Specified by:
isRequiredIndicatorVisible
in interfaceHasValue<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 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 ownsetRequired
method which should be called in case the client-side validation is required.- Specified by:
setRequiredIndicatorVisible
in interfaceHasValue<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 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<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 thisHasValue
is in read-only mode or not.- Specified by:
isReadOnly
in interfaceHasValue<HasValue.ValueChangeEvent<V>,
V> - Returns:
false
if the user can modify the value,true
if not.
-
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<HasValue.ValueChangeEvent<V>,
V> - Returns:
- empty value
-