Class Select<T>
- Type Parameters:
T
- the type of the items for the select
- All Implemented Interfaces:
AttachNotifier
,BlurNotifier<Select<T>>
,DetachNotifier
,Focusable<Select<T>>
,FocusNotifier<Select<T>>
,HasAriaLabel
,HasComponents
,HasElement
,HasEnabled
,HasHelper
,HasLabel
,HasPlaceholder
,HasSize
,HasStyle
,HasTheme
,HasValidation
,HasValue<AbstractField.ComponentValueChangeEvent<Select<T>,
,T>, T> HasValueAndElement<AbstractField.ComponentValueChangeEvent<Select<T>,
,T>, T> HasClientValidation
,HasOverlayClassName
,HasPrefix
,HasThemeVariant<SelectVariant>
,HasTooltip
,HasValidationProperties
,InputField<AbstractField.ComponentValueChangeEvent<Select<T>,
,T>, T> HasItemComponents<T>
,HasValidator<T>
,HasDataView<T,
,Void, SelectDataView<T>> HasListDataView<T,
,SelectListDataView<T>> SingleSelect<Select<T>,
,T> Serializable
Validation
Select comes with a built-in validation mechanism that verifies that the
field is not empty when required
is enabled.
Validation is triggered whenever the user initiates a value change, for example by selecting an item from the dropdown. Programmatic value changes trigger validation as well. If validation fails, the component is marked as invalid and an error message is displayed below the input.
The required error message can be configured using either
Select.SelectI18n.setRequiredErrorMessage(String)
or
HasValidationProperties.setErrorMessage(String)
.
For more advanced validation that requires custom rules, you can use
Binder
. Please note that Binder provides its own API for the required
validation, see asRequired()
.
However, if Binder doesn't fit your needs and you want to implement fully
custom validation logic, you can disable the built-in validation by setting
setManualValidation(boolean)
to true. This will allow you to control
the invalid state and the error message manually using
HasValidationProperties.setInvalid(boolean)
and HasValidationProperties.setErrorMessage(String)
API.
- Author:
- Vaadin Ltd.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
invalid-changed
event is sent when the invalid state changes.static class
opened-changed
event is sent when the overlay opened state changes.static class
The internationalization properties forSelect
.Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
AbstractField.ComponentValueChangeEvent<C extends Component,
V> Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
BlurNotifier.BlurEvent<C extends Component>
Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
FocusNotifier.FocusEvent<C extends Component>
Nested classes/interfaces inherited from interface com.vaadin.flow.component.shared.HasClientValidation
HasClientValidation.ClientValidatedEvent
Nested classes/interfaces inherited from interface com.vaadin.flow.data.binder.HasItemComponents
HasItemComponents.ItemComponent<T>
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSelect()
Constructs a select.Constructs a select with the initial value change listener.Select
(String label, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<Select<T>, T>> listener) Constructs a select with the initial label text and value change listener.Select
(String label, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<Select<T>, T>> listener, T... items) Constructs a select with the initial label text and value change listener. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the given components as children of this component.void
addComponentAsFirst
(Component component) Adds the given component as the first child of this component.void
addComponentAtIndex
(int index, Component component) Adds the given component as child of this component at the specific index.void
addComponents
(T afterItem, Component... components) Adds the components after the given item.protected Registration
Adds a listener forinvalid-changed
events fired by the webcomponent.protected Registration
Adds a listener foropened-changed
events fired by the webcomponent.Gets the aria-label of the component.Gets the aria-labelledby of the componentGets the child components of this component.DataProvider<T,
?> Gets the data provider used by this Select.Returns a validator that checks the state of the Value.Gets the generic data view for theSelect
.getI18n()
Gets the internationalization object previously set for this component.Returns the item enabled predicate.Gets the item label generator.int
getItemPosition
(T item) Gets the index of the child element that represents the given item.ComponentRenderer<? extends Component,
T> Returns the item component renderer.getLabel()
Gets the string for the label element.Gets the list data view for theSelect
.protected boolean
Checks whether the element property has a value that can be converted to the model type.boolean
Gets whether this select has been set to autofocus when the page loads.boolean
Returns whether the user is allowed to select nothing.boolean
Returns whether the overlay should overlap the input elementprotected boolean
isOpened()
Whether the dropdown is opened or not.boolean
Gets whether the user is required to provide a value.protected void
onAttach
(AttachEvent attachEvent) Called when the component is attached to a UI.void
onEnabledStateChanged
(boolean enabled) Handle component enable state when the enabled state changes.void
prependComponents
(T beforeItem, Component... components) Adds the components before the given item.void
Removes the given child components from this component.void
Removes all child components that are not items.void
setAriaLabel
(String ariaLabel) Set the aria-label of the component to the given text.void
setAriaLabelledBy
(String ariaLabelledBy) Set the aria-labelledby of the component.void
setAutofocus
(boolean autofocus) Sets the select to have focus when the page loads.void
setDataProvider
(DataProvider<T, ?> dataProvider) Sets a generic data provider for the Select to use.void
setEmptySelectionAllowed
(boolean emptySelectionAllowed) Sets whether the user is allowed to select nothing.void
setEmptySelectionCaption
(String emptySelectionCaption) Sets the empty selection caption whensetEmptySelectionAllowed(boolean)
has been enabled.void
setI18n
(Select.SelectI18n i18n) Sets the internationalization object for this component.void
setItemEnabledProvider
(SerializablePredicate<T> itemEnabledProvider) Sets the item enabled predicate for this select.void
setItemLabelGenerator
(ItemLabelGenerator<T> itemLabelGenerator) Sets the item label generator.setItems
(DataProvider<T, Void> dataProvider) Set a generic data provider for the component to use and returns the baseDataView
that provides API to get information on the items.setItems
(InMemoryDataProvider<T> inMemoryDataProvider) Sets an in-memory data provider for the component to usesetItems
(ListDataProvider<T> dataProvider) Sets a ListDataProvider for the component to use and returns aListDataView
that provides information and allows operations on the items.void
Sets the string for the label element.void
setManualValidation
(boolean enabled) Sets whether manual validation mode is enabled for the component.void
setNoVerticalOverlap
(boolean noVerticalOverlap) Defines whether the overlay should overlap the input element in the y-axis, or be positioned right above/below it.protected void
setOpened
(boolean opened) Set true to open the dropdown overlay.void
setOverlayWidth
(float width, Unit unit) Sets the dropdown overlay width.void
setOverlayWidth
(String width) Sets the dropdown overlay width.void
setPlaceholder
(String placeholder) Sets the placeholder hint for the user.void
setRenderer
(ComponentRenderer<? extends Component, T> renderer) Sets the item renderer for this select group.void
setRequiredIndicatorVisible
(boolean required) Sets whether the user is required to provide a value.void
setTextRenderer
(ItemLabelGenerator<T> itemLabelGenerator) Convenience setter for creating aTextRenderer
from the given function that converts the item to a string.protected void
validate()
Validates the current value against the constraints and sets theinvalid
property and theerrorMessage
property based on the result.protected boolean
valueEquals
(T value1, T value2) Compares two value instances to each other to determine whether they are equal.Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, setPresentationValue, setSynchronizedEvent
Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible
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.AttachNotifier
addAttachListener
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
Methods inherited from interface com.vaadin.flow.component.shared.HasClientValidation
addClientValidatedEventListener
Methods inherited from interface com.vaadin.flow.component.HasComponents
add, add, remove
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
Methods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperText
Methods inherited from interface com.vaadin.flow.data.provider.HasListDataView
setItems, setItems
Methods inherited from interface com.vaadin.flow.component.shared.HasOverlayClassName
getOverlayClassName, setOverlayClassName
Methods inherited from interface com.vaadin.flow.component.HasPlaceholder
getPlaceholder
Methods inherited from interface com.vaadin.flow.component.shared.HasPrefix
getPrefixComponent, setPrefixComponent
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, removeThemeVariants
Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipText
Methods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalid
Methods inherited from interface com.vaadin.flow.data.binder.HasValidator
addValidationStatusChangeListener
Methods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValue
Methods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, setReadOnly
-
Field Details
-
LABEL_ATTRIBUTE
- See Also:
-
-
Constructor Details
-
Select
public Select()Constructs a select. -
Select
public Select(HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<Select<T>, T>> listener) Constructs a select with the initial value change listener.- Parameters:
listener
- the value change listener to add- See Also:
-
Select
public Select(String label, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<Select<T>, T>> listener) Constructs a select with the initial label text and value change listener.- Parameters:
label
- the label describing the selectlistener
- the value change listener to add- See Also:
-
Select
@SafeVarargs public Select(String label, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<Select<T>, T>> listener, T... items) Constructs a select with the initial label text and value change listener.- Parameters:
label
- the label describing the selectlistener
- the value change listener to additems
- the items to be shown in the list of the select- See Also:
-
-
Method Details
-
getItemRenderer
Returns the item component renderer.- Returns:
- the item renderer or
null
if none set - See Also:
-
setRenderer
Sets the item renderer for this select group. The renderer is applied to each item to create a component which represents the item option in the select's drop down.Default is
null
which means that the item'sObject.toString()
method is used and set as the text content of the vaadin item element.- Parameters:
renderer
- the item renderer, ornull
to clear
-
setTextRenderer
Convenience setter for creating aTextRenderer
from the given function that converts the item to a string.NOTE: even though this accepts an
ItemLabelGenerator
, this is not the same assetItemLabelGenerator(ItemLabelGenerator)
which does a different thing.- Parameters:
itemLabelGenerator
- the function that creates the text content from the item, notnull
-
setEmptySelectionAllowed
public void setEmptySelectionAllowed(boolean emptySelectionAllowed) Sets whether the user is allowed to select nothing. When settrue
a special empty item is shown to the user.Default is
false
. The empty selection item can be customized withsetEmptySelectionCaption(String)
.- Parameters:
emptySelectionAllowed
-true
to allow not selecting anything,false
to require selection- See Also:
-
isEmptySelectionAllowed
public boolean isEmptySelectionAllowed()Returns whether the user is allowed to select nothing.- Returns:
true
if empty selection is allowed,false
otherwise
-
setEmptySelectionCaption
Sets the empty selection caption whensetEmptySelectionAllowed(boolean)
has been enabled. The caption is shown for the empty selection item in the drop down.When the empty selection item is selected, the select shows the value provided by
setItemLabelGenerator(ItemLabelGenerator)
for thenull
item, or the string set withsetPlaceholder(String)
or an empty string if not placeholder is set.Default is an empty string "", which will show the place holder when selected.
- Parameters:
emptySelectionCaption
- the empty selection caption to set, notnull
- See Also:
-
getEmptySelectionCaption
-
getItemEnabledProvider
Returns the item enabled predicate.- Returns:
- the item enabled predicate or
null
if not set - See Also:
-
setItemEnabledProvider
Sets the item enabled predicate for this select. The predicate is applied to each item to determine whether the item should be enabled (true
) or disabled (false
). Disabled items are displayed as grayed out and the user cannot select them.By default is
null
and all the items are enabled.- Parameters:
itemEnabledProvider
- the item enable predicate ornull
to clear
-
getItemLabelGenerator
Gets the item label generator. It generates the text that is shown in the input part for the item when it has been selected.Default is
null
.- Returns:
- the item label generator,
null
if not set
-
setItemLabelGenerator
Sets the item label generator. It generates the text that is shown in the input part for the item when it has been selected.Default is
null
and the text content generated for the item withsetRenderer(ComponentRenderer)
is used instead.- Parameters:
itemLabelGenerator
- the item label generator to set, ornull
to clear
-
setPlaceholder
Sets the placeholder hint for the user.The placeholder will be displayed in the case that there is no item selected, or the selected item has an empty string label, or the selected item has no label and it's DOM content is empty.
Default value is
null
.- Specified by:
setPlaceholder
in interfaceHasPlaceholder
- Parameters:
placeholder
- the placeholder to set, ornull
to remove
-
setLabel
Sets the string for the label element.NOTE: the label must be set for the required indicator to be visible.
-
getLabel
Gets the string for the label element. -
setAriaLabel
Description copied from interface:HasAriaLabel
Set the aria-label of the component to the given text.This method should not be used if
HasAriaLabel.setAriaLabelledBy(String)
is also used. If both attributes are present, aria-labelledby will take precedence over aria-label.- Specified by:
setAriaLabel
in interfaceHasAriaLabel
- Parameters:
ariaLabel
- the aria-label text to set ornull
to clear
-
getAriaLabel
Description copied from interface:HasAriaLabel
Gets the aria-label of the component.- Specified by:
getAriaLabel
in interfaceHasAriaLabel
- Returns:
- an optional aria-label of the component if no aria-label has been set
-
setAriaLabelledBy
Description copied from interface:HasAriaLabel
Set the aria-labelledby of the component. The value must be a valid id attribute of another element that labels the component. The label element must be in the same DOM scope of the component, otherwise screen readers may fail to announce the label content properly.This method should not be used if
HasAriaLabel.setAriaLabel(String)
is also used. If both attributes are present, aria-labelledby will take precedence over aria-label.- Specified by:
setAriaLabelledBy
in interfaceHasAriaLabel
- Parameters:
ariaLabelledBy
- the string with the id of the element that will be used as label ornull
to clear
-
getAriaLabelledBy
Description copied from interface:HasAriaLabel
Gets the aria-labelledby of the component- Specified by:
getAriaLabelledBy
in interfaceHasAriaLabel
- Returns:
- an optional aria-labelledby of the component if no aria-labelledby has been set
-
setAutofocus
public void setAutofocus(boolean autofocus) Sets the select to have focus when the page loads.Default is
false
.- Parameters:
autofocus
- the autofocus to set
-
isAutofocus
public boolean isAutofocus()Gets whether this select has been set to autofocus when the page loads.- Returns:
true
if set to autofocus,false
if not
-
setNoVerticalOverlap
public void setNoVerticalOverlap(boolean noVerticalOverlap) Defines whether the overlay should overlap the input element in the y-axis, or be positioned right above/below it.- Parameters:
noVerticalOverlap
- whether the overlay should overlap the input element
-
isNoVerticalOverlap
public boolean isNoVerticalOverlap()Returns whether the overlay should overlap the input element- Returns:
true
if the overlay should overlap the input element,false
otherwise
-
setDataProvider
Sets a generic data provider for the Select to use.Use this method when none of the
setItems
methods are applicable, e.g. when having a data provider with filter that cannot be transformed toDataProvider<T, Void>
.- Parameters:
dataProvider
- DataProvider instance to use, notnull
-
getDataProvider
Gets the data provider used by this Select.To get information and control over the items in the Select, use either
getListDataView()
orgetGenericDataView()
instead.- Returns:
- the data provider used by this Select
-
setItems
Description copied from interface:HasDataView
Set a generic data provider for the component to use and returns the baseDataView
that provides API to get information on the items.This method should be used only when the data provider type is not either
ListDataProvider
orBackEndDataProvider
.- Specified by:
setItems
in interfaceHasDataView<T,
Void, SelectDataView<T>> - Parameters:
dataProvider
- DataProvider instance to use, notnull
- Returns:
- DataView providing information on the data
-
setItems
Description copied from interface:HasDataView
Sets an in-memory data provider for the component to useNote! Using a
ListDataProvider
instead of aInMemoryDataProvider
is recommended to get access toListDataView
API by usingHasListDataView.setItems(ListDataProvider)
.- Specified by:
setItems
in interfaceHasDataView<T,
Void, SelectDataView<T>> - Parameters:
inMemoryDataProvider
- InMemoryDataProvider to use, notnull
- Returns:
- DataView providing information on the data
-
setItems
Description copied from interface:HasListDataView
Sets a ListDataProvider for the component to use and returns aListDataView
that provides information and allows operations on the items.- Specified by:
setItems
in interfaceHasListDataView<T,
SelectListDataView<T>> - Parameters:
dataProvider
- ListDataProvider providing items to the component.- Returns:
- ListDataView providing access to the items
-
getGenericDataView
Gets the generic data view for theSelect
. This data view should only be used whengetListDataView()
is not applicable for the underlying data provider.- Specified by:
getGenericDataView
in interfaceHasDataView<T,
Void, SelectDataView<T>> - Returns:
- the generic DataView instance implementing
Select
-
getListDataView
Gets the list data view for theSelect
. This data view should only be used when the items are in-memory and set with: If the items are not in-memory, an exception is thrown.- Specified by:
getListDataView
in interfaceHasListDataView<T,
SelectListDataView<T>> - Returns:
- the list data view that provides access to the data bound to the
Select
-
onEnabledStateChanged
public void onEnabledStateChanged(boolean enabled) Description copied from class:Component
Handle component enable state when the enabled state changes.By default this sets or removes the 'disabled' attribute from the element. This can be overridden to have custom handling.
- Overrides:
onEnabledStateChanged
in classComponent
- Parameters:
enabled
- the new enabled state of the component
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean required) Sets whether the user is required to provide a value. When required, an indicator appears next to the label and the field invalidates if the value is cleared.NOTE: The required indicator is only visible when the field has a label, see
setLabel(String)
.- Specified by:
setRequiredIndicatorVisible
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<Select<T>,
T>, T> - Specified by:
setRequiredIndicatorVisible
in interfaceHasValueAndElement<AbstractField.ComponentValueChangeEvent<Select<T>,
T>, T> - Parameters:
required
-true
to make the field required,false
otherwise
-
isRequiredIndicatorVisible
public boolean isRequiredIndicatorVisible()Gets whether the user is required to provide a value.- Specified by:
isRequiredIndicatorVisible
in interfaceHasValue<AbstractField.ComponentValueChangeEvent<Select<T>,
T>, T> - Specified by:
isRequiredIndicatorVisible
in interfaceHasValueAndElement<AbstractField.ComponentValueChangeEvent<Select<T>,
T>, T> - Returns:
true
if the field is required,false
otherwise- See Also:
-
add
Adds the given components as children of this component.In case any of the specified components has already been added to another parent, it will be removed from there and added to this one.
NOTE: If you add a component with the
slot
attribute set, it will be placed in the light-dom of thevaadin-select
instead of the dropdown.- Specified by:
add
in interfaceHasComponents
- Parameters:
components
- the components to add
-
addComponents
Description copied from interface:HasItemComponents
Adds the components after the given item.- Specified by:
addComponents
in interfaceHasItemComponents<T>
- Parameters:
afterItem
- item to add components aftercomponents
- components to add after item
-
prependComponents
Description copied from interface:HasItemComponents
Adds the components before the given item.- Specified by:
prependComponents
in interfaceHasItemComponents<T>
- Parameters:
beforeItem
- item to add components in front ofcomponents
- components to add before item
-
getItemPosition
Description copied from interface:HasItemComponents
Gets the index of the child element that represents the given item.- Specified by:
getItemPosition
in interfaceHasItemComponents<T>
- Parameters:
item
- the item to look for- Returns:
- the index of the child element that represents the item, or -1 if the item is not found
-
addComponentAtIndex
Adds the given component as child of this component at the specific index.In case the specified component has already been added to another parent, it will be removed from there and added to this one.
NOTE: If you add a component with the
slot
attribute set, it will be placed in the light-dom of thevaadin-select
instead of the dropdown.- Specified by:
addComponentAtIndex
in interfaceHasComponents
- Parameters:
index
- the index, where the component will be added. The index must be non-negative and may not exceed the children countcomponent
- the component to add, value should not be null
-
addComponentAsFirst
Adds the given component as the first child of this component.In case the specified component has already been added to another parent, it will be removed from there and added to this one.
NOTE: If you add a component with the
slot
attribute set, it will be placed in the light-dom of thevaadin-select
instead of the dropdown.- Specified by:
addComponentAsFirst
in interfaceHasComponents
- Parameters:
component
- the component to add, value should not be null
-
getChildren
Description copied from class:Component
Gets the child components of this component.The default implementation finds child components by traversing each child
Element
tree.If the component is injected to a PolymerTemplate using the
@Id
annotation the getChildren method will only return children added from the server side and will not return any children declared in the template file.- Overrides:
getChildren
in classComponent
- Returns:
- the child components of this component
- See Also:
-
remove
Removes the given child components from this component.NOTE: any component with the
slot
attribute will be attempted to removed from the light dom of the vaadin-select, instead of inside the options drop down.- Specified by:
remove
in interfaceHasComponents
- Parameters:
components
- the components to remove- Throws:
IllegalArgumentException
- if any of the components is not a child of this component
-
removeAll
public void removeAll()Removes all child components that are not items. To remove all items, reset the data provider or useHasListDataView.setItems(Object[])
.NOTE: this will remove all non-items from the drop down and any slotted components from vaadin-select's light dom.
- Specified by:
removeAll
in interfaceHasComponents
- See Also:
-
setOverlayWidth
Sets the dropdown overlay width.- Parameters:
width
- the new dropdown width. Pass in null to set the dropdown width back to the default value.
-
setOverlayWidth
Sets the dropdown overlay width. Negative number implies unspecified size (the dropdown width is reverted back to the default value).- Parameters:
width
- the width of the dropdown.unit
- the unit used for the dropdown.
-
setOpened
protected void setOpened(boolean opened) Set true to open the dropdown overlay.- Parameters:
opened
- the boolean value to set
-
isOpened
Whether the dropdown is opened or not.- Returns:
true
if the drop-down is opened,false
otherwise
-
hasValidValue
protected boolean hasValidValue()Description copied from class:AbstractSinglePropertyField
Checks whether the element property has a value that can be converted to the model type. Property changes from the element will be ignored if this method returnsfalse
. The default implementation always returntrue
.- Overrides:
hasValidValue
in classAbstractSinglePropertyField<Select<T>,
T> - Returns:
true
if the element property value can be converted to the model type; otherwisefalse
-
onAttach
Description copied from class:Component
Called when the component is attached to a UI.This method is invoked before the
Make sure to callAttachEvent
is fired for the component.super.onAttach
when overriding this method. -
valueEquals
Compares two value instances to each other to determine whether they are equal. Equality is used to determine whether to update internal state and fire an event whenAbstractField.setValue(Object)
orAbstractField.setModelValue(Object, boolean)
is called. Subclasses can override this method to define an alternative comparison method instead ofObject.equals(Object)
.- Overrides:
valueEquals
in classAbstractField<Select<T>,
T> - Parameters:
value1
- the first instancevalue2
- the second instance- Returns:
true
if the instances are equal; otherwisefalse
-
setManualValidation
public void setManualValidation(boolean enabled) Description copied from interface:HasValidation
Sets whether manual validation mode is enabled for the component.When enabled, the component doesn't perform its built-in constraint validation on value change, blur, and other events. This allows manually controlling the invalid state and error messages using the
HasValidation.setInvalid(boolean)
andHasValidation.setErrorMessage(String)
methods. Manual mode is helpful when there is a need for a totally custom validation logic that cannot be achieved with Binder.Example:
Field field = new Field(); field.setManualValidation(true); field.addValueChangeListener(event -> { if (Objects.equal(event.getValue(), "")) { field.setInvalid(true); field.setErrorMessage("The field is required."); } else { field.setInvalid(false); } });
For components that don't have built-in validation, the method has no effect.
- Specified by:
setManualValidation
in interfaceHasValidation
- Parameters:
enabled
- whether to enable manual validation mode.
-
getDefaultValidator
Description copied from interface:HasValidator
Returns a validator that checks the state of the Value. 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 aBinder
and can be seen as a validation failure.- Specified by:
getDefaultValidator
in interfaceHasValidator<T>
- Returns:
- state validator
-
validate
protected void validate()Validates the current value against the constraints and sets theinvalid
property and theerrorMessage
property based on the result. If a custom error message is provided withHasValidationProperties.setErrorMessage(String)
, it is used. Otherwise, the error message defined in the i18n object is used.The method does nothing if the manual validation mode is enabled.
-
addOpenedChangeListener
protected Registration addOpenedChangeListener(ComponentEventListener<Select.OpenedChangeEvent> listener) Adds a listener foropened-changed
events fired by the webcomponent.- Parameters:
listener
- the listener- Returns:
- a
Registration
for removing the event listener
-
addInvalidChangeListener
protected Registration addInvalidChangeListener(ComponentEventListener<Select.InvalidChangeEvent> listener) Adds a listener forinvalid-changed
events fired by the webcomponent.- Parameters:
listener
- the listener- Returns:
- a
Registration
for removing the event listener
-
getI18n
Gets the internationalization object previously set for this component.NOTE: Updating the instance that is returned from this method will not update the component if not set again using
setI18n(SelectI18n)
- Returns:
- the i18n object or
null
if no i18n object has been set
-
setI18n
Sets the internationalization object for this component.- Parameters:
i18n
- the i18n object, notnull
-