Interface HasValue<E extends HasValue.ValueChangeEvent<V>,V>
- Type Parameters:
E
- the type of the value change event fired by this instanceV
- the value type
- All Superinterfaces:
Serializable
- All Known Subinterfaces:
HasValueAndElement<E,
,V> InputField<E,
,V> MultiSelect<C,
,T> SingleSelect<C,
T>
- All Known Implementing Classes:
AbstractCompositeField
,AbstractField
,AbstractNumberField
,AbstractSinglePropertyField
,BigDecimalField
,Checkbox
,CheckboxGroup
,ComboBox
,ComboBoxBase
,CustomField
,DatePicker
,DateTimePicker
,EmailField
,Input
,IntegerField
,ListBox
,ListBoxBase
,MultiSelectComboBox
,MultiSelectListBox
,NumberField
,PasswordField
,RadioButtonGroup
,RangeInput
,ReadOnlyHasValue
,RichTextEditor
,Select
,TextArea
,TextField
,TextFieldBase
,TimePicker
- Since:
- 1.0.
- Author:
- Vaadin Ltd
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
An event fired when the value of aHasValue
changes.static interface
HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
A listener for value change events. -
Method Summary
Modifier and TypeMethodDescriptionaddValueChangeListener
(HasValue.ValueChangeListener<? super E> listener) Adds a value change listener.default void
clear()
Resets the value to the empty one.default V
Returns the value that represents an empty value.Returns the current value of this object, wrapped in anOptional
.getValue()
Returns the current value of this object.default boolean
isEmpty()
Returns whether thisHasValue
is considered to be empty.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.
-
Method Details
-
setValue
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
getEmptyValue()
if the empty value is notnull
.- Parameters:
value
- the new value- Throws:
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, and override
getEmptyValue()
if the empty value is notnull
.- Returns:
- the current value
-
addValueChangeListener
Adds a value change listener. The listener is called when the value of thisHasValue
is changed either by the user or programmatically.- Parameters:
listener
- the value change listener, not null- Returns:
- a registration for the listener
-
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
-
getOptionalValue
Returns the current value of this object, wrapped in anOptional
.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 thisHasValue
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
-
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:
-
setReadOnly
void setReadOnly(boolean readOnly) 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.- Parameters:
readOnly
- a boolean value specifying whether the component is put read-only mode or not
-
isReadOnly
boolean isReadOnly()Returns whether thisHasValue
is in read-only mode or not.- Returns:
false
if the user can modify the value,true
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.
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.- 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
-