T - the type of the items for the select@JavaScript(value="frontend://selectConnector.js") public class Select<T> extends GeneratedVaadinSelect<Select<T>,T> implements com.vaadin.flow.data.binder.HasDataProvider<T>, com.vaadin.flow.data.binder.HasItemsAndComponents<T>, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasValidation, com.vaadin.flow.data.selection.SingleSelect<Select<T>,T>, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.data.binder.HasValidator<T>, HasClientValidation
This is a server side Java integration for <vaadin-select> web
component.
For usage examples, see the demo in vaadin.com.
GeneratedVaadinSelect.InvalidChangeEvent<R extends GeneratedVaadinSelect<R,?>>, GeneratedVaadinSelect.OpenedChangeEvent<R extends GeneratedVaadinSelect<R,?>>com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V>com.vaadin.flow.data.binder.HasItemsAndComponents.ItemComponent<T>com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>HasClientValidation.ClientValidatedEvent| Modifier and Type | Field and Description |
|---|---|
static String |
LABEL_ATTRIBUTE |
| Constructor and Description |
|---|
Select()
Constructs a select.
|
Select(T... items)
Constructs a select with the given items.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(com.vaadin.flow.component.Component... components) |
void |
addComponentAsFirst(com.vaadin.flow.component.Component component) |
void |
addComponentAtIndex(int index,
com.vaadin.flow.component.Component component) |
void |
addComponents(T afterItem,
com.vaadin.flow.component.Component... components) |
void |
addToPrefix(com.vaadin.flow.component.Component... components)
Adds the given components as children of this component at the slot
'prefix'.
|
com.vaadin.flow.shared.Registration |
addValidationStatusChangeListener(com.vaadin.flow.data.binder.ValidationStatusChangeListener<T> listener) |
Stream<com.vaadin.flow.component.Component> |
getChildren() |
com.vaadin.flow.data.provider.DataProvider<T,?> |
getDataProvider()
Gets the data provider.
|
String |
getEmptySelectionCaption() |
String |
getErrorMessage()
Gets the error message to show to the user on invalid selection
|
com.vaadin.flow.function.SerializablePredicate<T> |
getItemEnabledProvider()
Returns the item enabled predicate.
|
com.vaadin.flow.component.ItemLabelGenerator<T> |
getItemLabelGenerator()
Gets the item label generator.
|
int |
getItemPosition(T item) |
com.vaadin.flow.data.renderer.ComponentRenderer<? extends com.vaadin.flow.component.Component,T> |
getItemRenderer()
Returns the item component renderer.
|
String |
getLabel()
Gets the string for the label element.
|
String |
getPlaceholder()
Gets the placeholder hint set for the user.
|
protected boolean |
hasValidValue() |
boolean |
isAutofocus()
Gets whether this select has been set to autofocus when the page loads.
|
boolean |
isEmptySelectionAllowed()
Returns whether the user is allowed to select nothing.
|
protected boolean |
isEnforcedFieldValidationEnabled() |
boolean |
isInvalid()
Gets whether the select is currently in invalid state.
|
boolean |
isRequiredIndicatorVisible()
NOTE: The required indicator will not be visible, if the
setLabel(String) property is not set for the select. |
protected void |
onAttach(com.vaadin.flow.component.AttachEvent attachEvent) |
void |
onEnabledStateChanged(boolean enabled) |
void |
prependComponents(T beforeItem,
com.vaadin.flow.component.Component... components) |
void |
remove(com.vaadin.flow.component.Component... components)
Removes the given child components from this component.
|
void |
removeAll()
Removes all child components that are not items.
|
void |
setAutofocus(boolean autofocus)
Sets the select to have focus when the page loads.
|
void |
setDataProvider(com.vaadin.flow.data.provider.DataProvider<T,?> dataProvider) |
void |
setEmptySelectionAllowed(boolean emptySelectionAllowed)
Sets whether the user is allowed to select nothing.
|
void |
setEmptySelectionCaption(String emptySelectionCaption)
Sets the empty selection caption when
setEmptySelectionAllowed(boolean) has been enabled. |
void |
setErrorMessage(String errorMessage)
Sets the error message to show to the user on invalid selection.
|
void |
setInvalid(boolean invalid)
Sets the select to show as invalid state and display error message.
|
void |
setItemEnabledProvider(com.vaadin.flow.function.SerializablePredicate<T> itemEnabledProvider)
Sets the item enabled predicate for this select.
|
void |
setItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
Sets the item label generator.
|
void |
setLabel(String label)
Sets the string for the label element.
|
void |
setPlaceholder(String placeholder)
Sets the placeholder hint for the user.
|
void |
setRenderer(com.vaadin.flow.data.renderer.ComponentRenderer<? extends com.vaadin.flow.component.Component,T> renderer)
Sets the item renderer for this select group.
|
void |
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
NOTE: The required indicator will not be visible, if the
setLabel(String) property is not set for the select. |
void |
setTextRenderer(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
Convenience setter for creating a
TextRenderer from the given
function that converts the item to a string. |
protected void |
validate()
Description copied from corresponding location in WebComponent:
|
addInvalidChangeListener, addOpenedChangeListener, getErrorMessageString, getLabelString, getNameString, getPlaceholderString, isAutofocusBoolean, isDisabledBoolean, isInvalidBoolean, isOpenedBoolean, isReadonlyBoolean, isRequiredBoolean, render, setDisabled, setName, setOpened, setReadonly, setRequiredgetSynchronizationRegistration, setPresentationValue, setSynchronizedEventaddValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEqualsaddListener, fireEvent, from, get, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, set, setElement, setId, setVisibleclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullisReadOnly, setReadOnlyaddValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValuegetHelperComponent, getHelperText, setHelperComponent, setHelperTextaddClientValidatedEventListeneraddClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNamepublic static final String LABEL_ATTRIBUTE
public Select()
public Select(T... items)
items - the items for the selectpublic com.vaadin.flow.data.renderer.ComponentRenderer<? extends com.vaadin.flow.component.Component,T> getItemRenderer()
null if none setsetRenderer(ComponentRenderer)public void setRenderer(com.vaadin.flow.data.renderer.ComponentRenderer<? extends com.vaadin.flow.component.Component,T> renderer)
Default is null which means that the item's Object.toString()
method is used and set as the text content of the vaadin item element.
renderer - the item renderer, or null to clearpublic void setTextRenderer(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
TextRenderer from the given
function that converts the item to a string.
NOTE: even though this accepts an ItemLabelGenerator,
this is not the same as
setItemLabelGenerator(ItemLabelGenerator) which does a different
thing.
itemLabelGenerator - the function that creates the text content from the item, not
nullpublic void setEmptySelectionAllowed(boolean emptySelectionAllowed)
true
a special empty item is shown to the user.
Default is false. The empty selection item can be customized with
setEmptySelectionCaption(String).
emptySelectionAllowed - true to allow not selecting anything, false to
require selectionsetEmptySelectionCaption(String)public boolean isEmptySelectionAllowed()
true if empty selection is allowed, false
otherwisepublic void setEmptySelectionCaption(String emptySelectionCaption)
setEmptySelectionAllowed(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 the
null item, or the string set with setPlaceholder(String)
or an empty string if not placeholder is set.
Default is an empty string "", which will show the place holder when selected.
emptySelectionCaption - the empty selection caption to set, not nullsetEmptySelectionAllowed(boolean)public String getEmptySelectionCaption()
public com.vaadin.flow.function.SerializablePredicate<T> getItemEnabledProvider()
null if not setsetItemEnabledProvider(com.vaadin.flow.function.SerializablePredicate<T>)public void setItemEnabledProvider(com.vaadin.flow.function.SerializablePredicate<T> itemEnabledProvider)
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.
itemEnabledProvider - the item enable predicate or null to clearpublic com.vaadin.flow.component.ItemLabelGenerator<T> getItemLabelGenerator()
Default is null.
null if not setpublic void setItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
Default is null and the text content generated for the item with
setRenderer(ComponentRenderer) is used instead.
itemLabelGenerator - the item label generator to set, or null to clearpublic String getPlaceholder()
null if none setpublic void setPlaceholder(String placeholder)
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.
setPlaceholder in class GeneratedVaadinSelect<Select<T>,T>placeholder - the placeholder to set, or null to removepublic void setLabel(String label)
NOTE: the label must be set for the required indicator to be visible.
setLabel in interface com.vaadin.flow.component.HasLabelsetLabel in class GeneratedVaadinSelect<Select<T>,T>label - string or null to clear itpublic String getLabel()
getLabel in interface com.vaadin.flow.component.HasLabelnull if not setpublic void setAutofocus(boolean autofocus)
Default is false.
setAutofocus in class GeneratedVaadinSelect<Select<T>,T>autofocus - the autofocus to setpublic boolean isAutofocus()
true if set to autofocus, false if notpublic void setDataProvider(com.vaadin.flow.data.provider.DataProvider<T,?> dataProvider)
setDataProvider in interface com.vaadin.flow.data.binder.HasDataProvider<T>public com.vaadin.flow.data.provider.DataProvider<T,?> getDataProvider()
nullpublic void onEnabledStateChanged(boolean enabled)
onEnabledStateChanged in class com.vaadin.flow.component.Componentpublic void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
setLabel(String) property is not set for the select.setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>public boolean isRequiredIndicatorVisible()
setLabel(String) property is not set for the select.isRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>isRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>public void setErrorMessage(String errorMessage)
setErrorMessage in interface com.vaadin.flow.component.HasValidationsetErrorMessage in class GeneratedVaadinSelect<Select<T>,T>errorMessage - the error message or null to clear itpublic String getErrorMessage()
getErrorMessage in interface com.vaadin.flow.component.HasValidationnull if not setpublic void setInvalid(boolean invalid)
setInvalid in interface com.vaadin.flow.component.HasValidationsetInvalid in class GeneratedVaadinSelect<Select<T>,T>invalid - true for invalid, false for validpublic boolean isInvalid()
isInvalid in interface com.vaadin.flow.component.HasValidationtrue for invalid, false for validpublic void add(com.vaadin.flow.component.Component... components)
NOTE: If you add a component with the slot attribute
set, it will be placed in the light-dom of the vaadin-select
instead of the drop down, similar to addToPrefix(Component...)
add in interface com.vaadin.flow.component.HasComponentspublic void addComponents(T afterItem, com.vaadin.flow.component.Component... components)
addComponents in interface com.vaadin.flow.data.binder.HasItemsAndComponents<T>public void prependComponents(T beforeItem, com.vaadin.flow.component.Component... components)
prependComponents in interface com.vaadin.flow.data.binder.HasItemsAndComponents<T>public int getItemPosition(T item)
getItemPosition in interface com.vaadin.flow.data.binder.HasItemsAndComponents<T>public void addComponentAtIndex(int index,
com.vaadin.flow.component.Component component)
NOTE: If you add a component with the slot attribute
set, it will be placed in the light-dom of the vaadin-select
instead of the drop down, similar to addToPrefix(Component...)
addComponentAtIndex in interface com.vaadin.flow.component.HasComponentspublic void addComponentAsFirst(com.vaadin.flow.component.Component component)
NOTE: If you add a component with the slot attribute
set, it will be placed in the light-dom of the vaadin-select
instead of the drop down, similar to addToPrefix(Component...)
addComponentAsFirst in interface com.vaadin.flow.component.HasComponentspublic void addToPrefix(com.vaadin.flow.component.Component... components)
GeneratedVaadinSelectaddToPrefix in class GeneratedVaadinSelect<Select<T>,T>components - The components to add.public Stream<com.vaadin.flow.component.Component> getChildren()
getChildren in class com.vaadin.flow.component.Componentpublic void remove(com.vaadin.flow.component.Component... components)
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.
remove in interface com.vaadin.flow.component.HasComponentsremove in class GeneratedVaadinSelect<Select<T>,T>components - the components to removeIllegalArgumentException - if any of the components is not a child of this componentpublic void removeAll()
HasItems.setItems(Object[]).
NOTE: this will remove all non-items from the drop down and any slotted components from vaadin-select's light dom.
removeAll in interface com.vaadin.flow.component.HasComponentsremoveAll in class GeneratedVaadinSelect<Select<T>,T>HasComponents.removeAll()protected boolean hasValidValue()
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
onAttach in class com.vaadin.flow.component.Componentprotected void validate()
GeneratedVaadinSelectDescription copied from corresponding location in WebComponent:
Returns true if value is valid, and sets the invalid flag
appropriately.
This function is not supported by Flow because it returns a
boolean. Functions with return types different than void are
not supported at this moment.
validate in class GeneratedVaadinSelect<Select<T>,T>public com.vaadin.flow.shared.Registration addValidationStatusChangeListener(com.vaadin.flow.data.binder.ValidationStatusChangeListener<T> listener)
addValidationStatusChangeListener in interface com.vaadin.flow.data.binder.HasValidator<T>protected boolean isEnforcedFieldValidationEnabled()
Copyright © 2026. All rights reserved.