com.vaadin.data.
Interface HasValue<V>
-
Type Parameters:
V
- the value typeAll Superinterfaces:
All Known Subinterfaces:
MultiSelect<T>
,SingleSelect<V>
All Known Implementing Classes:
AbstractColorPicker
,AbstractDateField
,AbstractField
,AbstractLocalDateField
,AbstractLocalDateTimeField
,AbstractMultiSelect
,AbstractSingleSelect
,AbstractTextField
,CheckBox
,CheckBoxGroup
,ColorPicker
,ColorPickerArea
,ColorPickerGradient
,ColorPickerGrid
,ColorPickerHistory
,ColorPickerPopup
,ColorPickerPreview
,ColorPickerSelect
,ComboBox
,CustomField
,DateField
,DateTimeField
,GridMultiSelect
,GridSingleSelect
,InlineDateField
,InlineDateTimeField
,ListSelect
,NativeSelect
,PasswordField
,RadioButtonGroup
,ReadOnlyHasValue
,RichTextArea
,Slider
,TextArea
,TextField
,TwinColSelect
public interface HasValue<V> extends Serializable
A generic interface for field components and other user interface objects that have a user-editable value. Emits change events whenever the value is changed, either by the user or programmatically.
Since:
8.0
Author:
Vaadin Ltd.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
HasValue.ValueChangeEvent<V>
An event fired when the value of a
HasValue
changes.static interface
HasValue.ValueChangeListener<V>
A listener for value change events.
-
Method Summary
All Methods Modifier and Type Method Description Registration
addValueChangeListener(HasValue.ValueChangeListener<V> listener)
Adds a value change listener.
default void
clear()
Resets the value to the empty one.
default Validator<V>
getDefaultValidator()
Returns a validator that checks the internal state of the HasValue.
default V
getEmptyValue()
Returns the value that represents an empty value.
default Optional<V>
getOptionalValue()
Returns the current value of this object, wrapped in an
Optional
.V
getValue()
Returns the current value of this object.
default boolean
isEmpty()
Returns whether this
HasValue
is considered to be empty.boolean
isReadOnly()
Returns whether this
HasValue
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 this
HasValue
to given mode.void
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets the required indicator visible or not.
void
setValue(V value)
Sets the value of this object.
-
-
-
Method Detail
-
setValue
void setValue(V value)
Sets the value of this object. If the new value is not equal to
getValue()
, 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.
Parameters:
value
- the new valueThrows:
IllegalArgumentException
- if the value is invalid
-
getValue
V getValue()
Returns the current value of this object.
Implementation note: the implementing class should document whether null values may be returned or not.
Returns:
the current value
-
addValueChangeListener
Registration addValueChangeListener(HasValue.ValueChangeListener<V> listener)
Adds a value change listener. The listener is called when the value of this
HasValue
is changed either by the user or programmatically.Parameters:
listener
- the value change listener, not nullReturns:
a registration for the listener
-
getEmptyValue
default V getEmptyValue()
Returns the value that represents an empty value.
By default
HasValue
is expected to supportnull
as empty values. Specific implementations might not support this.Returns:
empty value
See Also:
-
getOptionalValue
default Optional<V> getOptionalValue()
Returns the current value of this object, wrapped in an
Optional
.The
Optional
will be empty if the value isnull
orisEmpty()
returnstrue
.Returns:
the current value, wrapped in an
Optional
-
isEmpty
default boolean isEmpty()
Returns whether this
HasValue
is considered to be empty.By default this is an equality check between current value and empty value.
Returns:
true
if considered empty;false
if not
-
setRequiredIndicatorVisible
void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets the required indicator visible or not.
If set visible, it is visually indicated in the user interface.
Parameters:
requiredIndicatorVisible
-true
to make the required indicator visible,false
if not
-
isRequiredIndicatorVisible
boolean isRequiredIndicatorVisible()
Checks whether the required indicator is visible.
Returns:
true
if visible,false
if not
-
setReadOnly
void setReadOnly(boolean readOnly)
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.Parameters:
readOnly
- a boolean value specifying whether the component is put read-only mode or not
-
isReadOnly
boolean isReadOnly()
Returns whether this
HasValue
is in read-only mode or not.Returns:
false
if the user can modify the value,true
if not.
-
clear
default void clear()
Resets the value to the empty one.
This is just a shorthand for resetting the value, see the methods
setValue(Object)
andgetEmptyValue()
.See Also:
-
getDefaultValidator
default Validator<V> getDefaultValidator()
Returns a validator that checks the internal state of the HasValue. This should be overridden for components with internal value conversion or validation, e.g. when the user is providing a string that has to be parsed into a date. An invalid input from user will be exposed to a
Binder
and can be seen as a validation failure.Returns:
internal state validator
Since:
8.1
See Also:
-
-