com.vaadin.flow.component.combobox.
Class ComboBox<T>
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.AbstractField<C,T>
-
- com.vaadin.flow.component.AbstractSinglePropertyField<R,T>
-
- com.vaadin.flow.component.combobox.GeneratedVaadinComboBox<ComboBox<T>,T>
-
- com.vaadin.flow.component.combobox.ComboBox<T>
-
Type Parameters:
T
- the type of the items to be inserted in the combo boxAll Implemented Interfaces:
AttachNotifier, BlurNotifier<ComboBox<T>>, DetachNotifier, Focusable<ComboBox<T>>, FocusNotifier<ComboBox<T>>, HasElement, HasEnabled, HasSize, HasStyle, HasValidation, HasValue<AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>,T>, HasValueAndElement<AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>,T>, HasDataProvider<T>, HasItems<T>, Serializable
@HtmlImport(value="frontend://flow-component-renderer.html") public class ComboBox<T> extends GeneratedVaadinComboBox<ComboBox<T>,T> implements HasSize, HasValidation, HasDataProvider<T>
Server-side component for the
vaadin-combo-box
webcomponent. It contains the same features of the webcomponent, such as item filtering, object selection and item templating.See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.flow.component.combobox.GeneratedVaadinComboBox
GeneratedVaadinComboBox.CustomValueSetEvent<R extends GeneratedVaadinComboBox<R,?>>, GeneratedVaadinComboBox.FilterChangeEvent<R extends GeneratedVaadinComboBox<R,?>>, GeneratedVaadinComboBox.InvalidChangeEvent<R extends GeneratedVaadinComboBox<R,?>>, GeneratedVaadinComboBox.OpenedChangeEvent<R extends GeneratedVaadinComboBox<R,?>>, GeneratedVaadinComboBox.SelectedItemChangeEvent<R extends GeneratedVaadinComboBox<R,?>>
-
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.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
-
-
Constructor Summary
Constructors Constructor and Description ComboBox()
Default constructor.
ComboBox(String label)
Creates an empty combo box with the defined label.
ComboBox(String label, Collection<T> items)
Creates a combo box with the defined label and populated with the items in the collection.
ComboBox(String label, T... items)
Creates a combo box with the defined label and populated with the items in the array.
-
Method Summary
All Methods Modifier and Type Method and Description Registration
addCustomValueSetListener(ComponentEventListener<GeneratedVaadinComboBox.CustomValueSetEvent<ComboBox<T>>> listener)
Adds a listener for CustomValueSetEvent which is fired when user types in a value that don't already exist in the ComboBox.
DataProvider<T,?>
getDataProvider()
T
getEmptyValue()
Returns the value that represents an empty value.
String
getErrorMessage()
Gets the current error message from the combobox.
List<T>
getFilteredItems()
Gets the list of items which were filtered by the user input.
ItemLabelGenerator<T>
getItemLabelGenerator()
Gets the item label generator that is used to produce the strings shown in the combo box for each item.
String
getLabel()
Gets the label of the combobox.
String
getPattern()
Gets the valid input pattern
String
getPlaceholder()
Gets the placeholder of the combobox.
T
getValue()
Returns the current value of this object.
boolean
isAllowCustomValue()
If
true
, the user can input a value that is not present in the items list.boolean
isAutofocus()
Get the state for the auto-focus property of the combobox.
boolean
isInvalid()
Gets the validity of the combobox output.
boolean
isOpened()
Gets the states of the drop-down.
boolean
isPreventInvalidInput()
Determines whether preventing the user from inputing invalid value.
boolean
isRequired()
Determines whether the combobox is marked as input required.
void
onEnabledStateChanged(boolean enabled)
Handle component enable state when the enabled state changes.
void
setAllowCustomValue(boolean allowCustomValue)
Description copied from corresponding location in WebComponent:
void
setAutofocus(boolean autofocus)
Set the combobox to be input focused when the page loads.
void
setDataProvider(DataProvider<T,?> dataProvider)
Sets the data provider for this listing.
void
setErrorMessage(String errorMessage)
Description copied from corresponding location in WebComponent:
void
setFilteredItems(Collection<T> filteredItems)
It sets the list of visible items in reaction of the input of the user.
void
setFilteredItems(T... filteredItems)
Convenience method for the
setFilteredItems(Collection)
.void
setInvalid(boolean invalid)
Description copied from corresponding location in WebComponent:
void
setItemLabelGenerator(ItemLabelGenerator<T> itemLabelGenerator)
Sets the item label generator that is used to produce the strings shown in the combo box for each item.
void
setLabel(String label)
Description copied from corresponding location in WebComponent:
void
setOpened(boolean opened)
Description copied from corresponding location in WebComponent:
void
setPattern(String pattern)
Description copied from corresponding location in WebComponent:
void
setPlaceholder(String placeholder)
Description copied from corresponding location in WebComponent:
void
setPreventInvalidInput(boolean preventInvalidInput)
Description copied from corresponding location in WebComponent:
void
setRenderer(Renderer<T> renderer)
Sets the TemplateRenderer responsible to render the individual items in the list of possible choices of the ComboBox.
void
setRequired(boolean required)
Description copied from corresponding location in WebComponent:
void
setValue(T value)
Sets the value of this object.
-
Methods inherited from class com.vaadin.flow.component.combobox.GeneratedVaadinComboBox
addFilterChangeListener, addInvalidChangeListener, addOpenedChangeListener, addSelectedItemChangeListener, addToPrefix, cancel, checkValidity, close, getErrorMessageString, getFilteredItemsJsonArray, getFilterString, getItemsJsonArray, getLabelString, getNameString, getPatternString, getPlaceholderString, isAllowCustomValueBoolean, isAutofocusBoolean, isDisabledBoolean, isInvalidBoolean, isLoadingBoolean, isOpenedBoolean, isPreventInvalidInputBoolean, isReadonlyBoolean, isRequiredBoolean, open, remove, removeAll, setDisabled, setFilter, setFilteredItems, setItems, setLoading, setName, setReadonly, validate
-
Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
hasValidValue, setPresentationValue, setSynchronizedEvent
-
Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, isEmpty, setModelValue, valueEquals
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onAttach, onDetach, 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.HasSize
getHeight, getWidth, setHeight, setSizeFull, setSizeUndefined, setWidth
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.data.binder.HasDataProvider
setItems
-
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.Focusable
blur, focus, getTabIndex, setTabIndex
-
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
-
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
-
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
-
Methods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
-
Methods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValue
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
-
-
-
Constructor Detail
-
ComboBox
public ComboBox()
Default constructor. Creates an empty combo box.
-
ComboBox
public ComboBox(String label)
Creates an empty combo box with the defined label.
Parameters:
label
- the label describing the combo box
-
ComboBox
public ComboBox(String label, Collection<T> items)
Creates a combo box with the defined label and populated with the items in the collection.
Parameters:
label
- the label describing the combo boxitems
- the items to be shown in the list of the combo boxSee Also:
-
ComboBox
@SafeVarargs public ComboBox(String label, T... items)
Creates a combo box with the defined label and populated with the items in the array.
Parameters:
label
- the label describing the combo boxitems
- the items to be shown in the list of the combo boxSee Also:
-
-
Method Detail
-
setRenderer
public void setRenderer(Renderer<T> renderer)
Sets the TemplateRenderer responsible to render the individual items in the list of possible choices of the ComboBox. It doesn't affect how the selected item is rendered - that can be configured by using
setItemLabelGenerator(ItemLabelGenerator)
.Parameters:
renderer
- a renderer for the items in the selection list of the ComboBox, notnull
-
setDataProvider
public void setDataProvider(DataProvider<T,?> dataProvider)
Description copied from interface:
HasDataProvider
Sets the data provider for this listing. The data provider is queried for displayed items as needed.
Specified by:
setDataProvider
in interfaceHasDataProvider<T>
Parameters:
dataProvider
- the data provider, not null
-
getDataProvider
public DataProvider<T,?> getDataProvider()
-
getFilteredItems
public List<T> getFilteredItems()
Gets the list of items which were filtered by the user input.
Returns:
the list of filtered items, or empty list if none were filtered
-
setFilteredItems
public void setFilteredItems(T... filteredItems)
Convenience method for the
setFilteredItems(Collection)
. It sets the list of visible items in reaction of the input of the user.Parameters:
filteredItems
- the items to show in response of a filter input
-
setFilteredItems
public void setFilteredItems(Collection<T> filteredItems)
It sets the list of visible items in reaction of the input of the user.
Parameters:
filteredItems
- the items to show in response of a filter input
-
setItemLabelGenerator
public void setItemLabelGenerator(ItemLabelGenerator<T> itemLabelGenerator)
Sets the item label generator that is used to produce the strings shown in the combo box for each item. By default,
String.valueOf(Object)
is used.When the
setRenderer(Renderer)
is used, the ItemLabelGenerator is only used to show the selected item label.Parameters:
itemLabelGenerator
- the item label provider to use, not null
-
getItemLabelGenerator
public ItemLabelGenerator<T> getItemLabelGenerator()
Gets the item label generator that is used to produce the strings shown in the combo box for each item.
Returns:
the item label generator used, not null
-
setOpened
public void setOpened(boolean opened)
Description copied from class:
GeneratedVaadinComboBox
Description copied from corresponding location in WebComponent:
True if the dropdown is open, false otherwise.
Overrides:
setOpened
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
opened
- the boolean value to set
-
isOpened
public boolean isOpened()
Gets the states of the drop-down.
Returns:
true
if the drop-down is opened,false
otherwise
-
setInvalid
public void setInvalid(boolean invalid)
Description copied from class:
GeneratedVaadinComboBox
Description copied from corresponding location in WebComponent:
Set to true if the value is invalid.
Specified by:
setInvalid
in interfaceHasValidation
Overrides:
setInvalid
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
invalid
- the boolean value to set
-
isInvalid
public boolean isInvalid()
Gets the validity of the combobox output.
return true, if the value is invalid.
Specified by:
isInvalid
in interfaceHasValidation
Returns:
the
validity
property from the component
-
setErrorMessage
public void setErrorMessage(String errorMessage)
Description copied from class:
GeneratedVaadinComboBox
Description copied from corresponding location in WebComponent:
The error message to display when the input is invalid.
Specified by:
setErrorMessage
in interfaceHasValidation
Overrides:
setErrorMessage
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
errorMessage
- the String value to set
-
getErrorMessage
public String getErrorMessage()
Gets the current error message from the combobox.
Specified by:
getErrorMessage
in interfaceHasValidation
Returns:
the current error message
-
setAllowCustomValue
public void setAllowCustomValue(boolean allowCustomValue)
Description copied from class:
GeneratedVaadinComboBox
Description copied from corresponding location in WebComponent:
If
true
, the user can input a value that is not present in the items list.value
property will be set to the input value in this case. Also, whenvalue
is set programmatically, the input value will be set to reflect that value.Overrides:
setAllowCustomValue
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
allowCustomValue
- the boolean value to set
-
isAllowCustomValue
public boolean isAllowCustomValue()
If
true
, the user can input a value that is not present in the items list.value
property will be set to the input value in this case. Also, whenvalue
is set programmatically, the input value will be set to reflect that value.This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
Returns:
the
allowCustomValue
property from the combobox
-
setAutofocus
public void setAutofocus(boolean autofocus)
Set the combobox to be input focused when the page loads.
Overrides:
setAutofocus
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
autofocus
- the boolean value to set
-
isAutofocus
public boolean isAutofocus()
Get the state for the auto-focus property of the combobox.
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
Returns:
the
autofocus
property from the combobox
-
setPreventInvalidInput
public void setPreventInvalidInput(boolean preventInvalidInput)
Description copied from class:
GeneratedVaadinComboBox
Description copied from corresponding location in WebComponent:
Set to true to prevent the user from entering invalid input.
Overrides:
setPreventInvalidInput
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
preventInvalidInput
- the boolean value to set
-
isPreventInvalidInput
public boolean isPreventInvalidInput()
Determines whether preventing the user from inputing invalid value.
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
Returns:
the
preventInvalidInput
property of the combobox
-
setRequired
public void setRequired(boolean required)
Description copied from class:
GeneratedVaadinComboBox
Description copied from corresponding location in WebComponent:
Set to true to mark the input as required.
Overrides:
setRequired
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
required
- the boolean value to set
-
isRequired
public boolean isRequired()
Determines whether the combobox is marked as input required.
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
Returns:
true
if the input is required,false
otherwise
-
setLabel
public void setLabel(String label)
Description copied from class:
GeneratedVaadinComboBox
Description copied from corresponding location in WebComponent:
The label for this element.
Overrides:
setLabel
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
label
- the String value to set
-
getLabel
public String getLabel()
Gets the label of the combobox.
Returns:
the
label
property of the combobox
-
setPlaceholder
public void setPlaceholder(String placeholder)
Description copied from class:
GeneratedVaadinComboBox
Description copied from corresponding location in WebComponent:
A placeholder string in addition to the label.
Overrides:
setPlaceholder
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
placeholder
- the String value to set
-
getPlaceholder
public String getPlaceholder()
Gets the placeholder of the combobox.
Returns:
the
placeholder
property of the combobox
-
setPattern
public void setPattern(String pattern)
Description copied from class:
GeneratedVaadinComboBox
Description copied from corresponding location in WebComponent:
A pattern to validate the
input
with.Overrides:
setPattern
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
pattern
- the String value to set
-
getPattern
public String getPattern()
Gets the valid input pattern
Returns:
the
pattern
property of the combobox
-
getEmptyValue
public T 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<AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>,T>
Overrides:
getEmptyValue
in classAbstractField<ComboBox<T>,T>
Returns:
empty value
-
setValue
public void setValue(T value)
Description copied from interface:
HasValue
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, and override
HasValue.getEmptyValue()
if the empty value is notnull
.
-
getValue
public T 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
.
-
addCustomValueSetListener
public Registration addCustomValueSetListener(ComponentEventListener<GeneratedVaadinComboBox.CustomValueSetEvent<ComboBox<T>>> listener)
Adds a listener for CustomValueSetEvent which is fired when user types in a value that don't already exist in the ComboBox.
As a side effect makes the ComboBox allow custom values. If you don't want to allow a user to add new values to the list once the listener is added please disable it explicitly via the
setAllowCustomValue(boolean)
method.The custom value becomes disallowed automatically once the last custom value set listener is removed.
Overrides:
addCustomValueSetListener
in classGeneratedVaadinComboBox<ComboBox<T>,T>
Parameters:
listener
- the listener to be notified when a new value is filledReturns:
a
Registration
for removing the event listenerSee Also:
-
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
-
-