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 box
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.BlurNotifier<ComboBox<T>>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<ComboBox<T>>,com.vaadin.flow.component.FocusNotifier<ComboBox<T>>,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasHelper,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,com.vaadin.flow.component.HasValidation,com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>,T>,com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>,T>,HasClearButton,com.vaadin.flow.data.provider.HasDataView<T,String,ComboBoxDataView<T>>,com.vaadin.flow.data.provider.HasLazyDataView<T,String,ComboBoxLazyDataView<T>>,com.vaadin.flow.data.provider.HasListDataView<T,ComboBoxListDataView<T>>,Serializable
@JsModule("./flow-component-renderer.js") @JsModule("./comboBoxConnector.js") public class ComboBox<T> extends GeneratedVaadinComboBox<ComboBox<T>,T> implements com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasValidation, com.vaadin.flow.data.provider.HasDataView<T,String,ComboBoxDataView<T>>, com.vaadin.flow.data.provider.HasListDataView<T,ComboBoxListDataView<T>>, com.vaadin.flow.data.provider.HasLazyDataView<T,String,ComboBoxLazyDataView<T>>, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasLabel, HasClearButtonCombo Box allows the user to choose a value from a filterable list of options presented in an overlay.ComboBox supports lazy loading. This means that when using large data sets, items are requested from the server one "page" at a time when the user scrolls down the overlay. The number of items in one page is by default 50, and can be changed with
setPageSize(int).ComboBox can do filtering either in the browser or in the server. When ComboBox has only a relatively small set of items, the filtering will happen in the browser, allowing smooth user-experience. When the size of the data set is larger than the
pageSize, the webcomponent doesn't necessarily have all the data available and it will make requests to the server to handle the filtering. Also, if you have defined custom filtering logic, with eg.setItems(ItemFilter, Collection), filtering will happen in the server. To enable client-side filtering with larger data sets, you can override thepageSizeto be bigger than the size of your data set. However, then the full data set will be sent to the client immediately and you will lose the benefits of lazy loading.- Author:
- Vaadin Ltd
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceComboBox.FetchItemsCallback<T>A callback method for fetching items.static interfaceComboBox.ItemFilter<T>Predicate to checkComboBoxitems against user typed strings.-
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
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V extends Object>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>
-
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>
-
-
Constructor Summary
Constructors Constructor Description ComboBox()Default constructor.ComboBox(int pageSize)Creates an empty combo box with the defined page size for lazy loading.ComboBox(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>> listener)Constructs a combo box with a value change listener.ComboBox(String label)Creates an empty combo box with the defined label.ComboBox(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>> listener)Constructs a combo box with the defined label and a value change listener.ComboBox(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>> listener, T... items)Constructs a combo box with the defined label, a value change listener and populated with the items in the array.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 Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description com.vaadin.flow.shared.RegistrationaddCustomValueSetListener(com.vaadin.flow.component.ComponentEventListener<GeneratedVaadinComboBox.CustomValueSetEvent<ComboBox<T>>> listener)Adds a listener for the event which is fired when user inputs a string value that does not match any existing items and commits it eg.voidaddThemeVariants(ComboBoxVariant... variants)Adds theme variants to the component.com.vaadin.flow.data.provider.DataProvider<T,?>getDataProvider()Gets the data provider used by this ComboBox.TgetEmptyValue()StringgetErrorMessage()Gets the current error message from the combobox.ComboBoxDataView<T>getGenericDataView()Gets the generic data view for the ComboBox.com.vaadin.flow.component.ItemLabelGenerator<T>getItemLabelGenerator()Gets the item label generator that is used to produce the strings shown in the combo box for each item.StringgetLabel()Gets the label of the combobox.ComboBoxLazyDataView<T>getLazyDataView()Gets the lazy data view for the ComboBox.ComboBoxListDataView<T>getListDataView()Gets the list data view for the ComboBox.intgetPageSize()Gets the page size, which is the number of items fetched at a time from the data provider.StringgetPattern()Gets the valid input patternStringgetPlaceholder()Gets the placeholder of the combobox.booleanisAllowCustomValue()Iftrue, the user can input string values that do not match to any existing item labels, which will fire aGeneratedVaadinComboBox.CustomValueSetEvent.booleanisAutofocus()Get the state for the auto-focus property of the combobox.booleanisAutoOpen()Gets whether dropdown will open automatically or not.booleanisInvalid()Gets the validity of the combobox output.booleanisOpened()Gets the states of the drop-down.booleanisPreventInvalidInput()Determines whether preventing the user from inputing invalid value.booleanisRequired()Determines whether the combobox is marked as input required.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent)protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent)voidremoveThemeVariants(ComboBoxVariant... variants)Removes theme variants from the component.voidsetAllowCustomValue(boolean allowCustomValue)Enables or disables the component firing events for custom string input.voidsetAutofocus(boolean autofocus)Set the combobox to be input focused when the page loads.voidsetAutoOpen(boolean autoOpen)Enables or disables the dropdown opening automatically.voidsetDataProvider(ComboBox.FetchItemsCallback<T> fetchItems, com.vaadin.flow.function.SerializableFunction<String,Integer> sizeCallback)Deprecated.use insteadsetItems(CallbackDataProvider.FetchCallback, CallbackDataProvider.CountCallback)which provide access toComboBoxLazyDataViewvoidsetDataProvider(ComboBox.ItemFilter<T> itemFilter, com.vaadin.flow.data.provider.ListDataProvider<T> listDataProvider)Deprecated.use insteadsetItems(ItemFilter, ListDataProvider)which provide access toComboBoxListDataView<C> voidsetDataProvider(com.vaadin.flow.data.provider.DataProvider<T,C> dataProvider, com.vaadin.flow.function.SerializableFunction<String,C> filterConverter)Deprecated.use instead one of thesetItemsmethods which provide access to eitherComboBoxListDataVieworComboBoxLazyDataViewvoidsetDataProvider(com.vaadin.flow.data.provider.DataProvider<T,String> dataProvider)Deprecated.use instead one of thesetItemsmethods which provide access to eitherComboBoxListDataVieworComboBoxLazyDataViewvoidsetDataProvider(com.vaadin.flow.data.provider.ListDataProvider<T> listDataProvider)Deprecated.use instead one of thesetItemsmethods which provide access toComboBoxListDataViewvoidsetErrorMessage(String errorMessage)Description copied from corresponding location in WebComponent:voidsetInvalid(boolean invalid)Description copied from corresponding location in WebComponent:voidsetItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)Sets the item label generator that is used to produce the strings shown in the combo box for each item.ComboBoxListDataView<T>setItems(ComboBox.ItemFilter<T> itemFilter, com.vaadin.flow.data.provider.ListDataProvider<T> listDataProvider)Sets a ListDataProvider for this combo box and a filtering function for defining which items are displayed when user types into the combo box.ComboBoxListDataView<T>setItems(ComboBox.ItemFilter<T> itemFilter, Collection<T> items)Sets the data items of this combo box and a filtering function for defining which items are displayed when user types into the combo box.ComboBoxListDataView<T>setItems(ComboBox.ItemFilter<T> itemFilter, T... items)Sets the data items of this combo box and a filtering function for defining which items are displayed when user types into the combo box.ComboBoxLazyDataView<T>setItems(com.vaadin.flow.data.provider.BackEndDataProvider<T,String> dataProvider)ComboBoxLazyDataView<T>setItems(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T,String> fetchCallback)Supply items lazily with a callback from a backend.ComboBoxLazyDataView<T>setItems(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T,String> fetchCallback, com.vaadin.flow.data.provider.CallbackDataProvider.CountCallback<T,String> countCallback)Supply items lazily with callbacks: the first one fetches the items based on offset, limit and an optional filter, the second provides the exact count of items in the backend.ComboBoxDataView<T>setItems(com.vaadin.flow.data.provider.DataProvider<T,String> dataProvider)ComboBoxDataView<T>setItems(com.vaadin.flow.data.provider.InMemoryDataProvider<T> dataProvider)Deprecated.does not work so don't useComboBoxDataView<T>setItems(com.vaadin.flow.data.provider.InMemoryDataProvider<T> inMemoryDataProvider, com.vaadin.flow.function.SerializableFunction<String,com.vaadin.flow.function.SerializablePredicate<T>> filterConverter)Sets an in-memory data provider for the combo box to use, taking into account both in-memory filtering from data provider and combo box's text filter.ComboBoxListDataView<T>setItems(com.vaadin.flow.data.provider.ListDataProvider<T> dataProvider)ComboBoxListDataView<T>setItems(Collection<T> items)voidsetItems(Stream<T> streamOfItems)Deprecated.Because the stream is collected to a list anyway, usesetItems(Collection)orsetItems(CallbackDataProvider.FetchCallback)instead.<C> ComboBoxLazyDataView<T>setItemsWithFilterConverter(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T,C> fetchCallback, com.vaadin.flow.data.provider.CallbackDataProvider.CountCallback<T,C> countCallback, com.vaadin.flow.function.SerializableFunction<String,C> filterConverter)Supply items lazily with callbacks: the first one fetches the items based on offset, limit and an optional filter, the second provides the exact count of items in the backend.<C> ComboBoxLazyDataView<T>setItemsWithFilterConverter(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T,C> fetchCallback, com.vaadin.flow.function.SerializableFunction<String,C> filterConverter)Supply items lazily with a callback from a backend, using custom filter type.voidsetLabel(String label)Sets the label for the combobox.voidsetOpened(boolean opened)Description copied from corresponding location in WebComponent:voidsetPageSize(int pageSize)Sets the page size, which is the number of items requested at a time from the data provider.voidsetPattern(String pattern)Description copied from corresponding location in WebComponent:voidsetPlaceholder(String placeholder)Description copied from corresponding location in WebComponent:voidsetPreventInvalidInput(boolean preventInvalidInput)Description copied from corresponding location in WebComponent:voidsetRenderer(Renderer<T> renderer)Sets the Renderer responsible to render the individual items in the list of possible choices of the ComboBox.voidsetRequired(boolean required)Description copied from corresponding location in WebComponent:voidsetRequiredIndicatorVisible(boolean requiredIndicatorVisible)voidsetValue(T value)-
Methods inherited from class com.vaadin.flow.component.combobox.GeneratedVaadinComboBox
addFilterChangeListener, addInvalidChangeListener, addOpenedChangeListener, addSelectedItemChangeListener, addToPrefix, cancel, checkValidity, clearCache, close, getErrorMessageString, getFilteredItemsJsonArray, getFilterString, getItemIdPathString, getItemLabelPathString, getItemsJsonArray, getItemValuePathString, getLabelString, getNameString, getPageSizeDouble, getPatternString, getPlaceholderString, getSelectedItemJsonObject, getSizeDouble, isAllowCustomValueBoolean, isAutofocusBoolean, isDisabledBoolean, isInvalidBoolean, isLoadingBoolean, isOpenedBoolean, isPreventInvalidInputBoolean, isReadonlyBoolean, isRequiredBoolean, open, remove, removeAll, setDisabled, setFilter, setFilteredItems, setItemIdPath, setItemLabelPath, setItems, setItemValuePath, setLoading, setName, setPageSize, setReadonly, setSelectedItem, setSize, validate
-
Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent
-
Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getValue, isEmpty, setModelValue, valueEquals
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, 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.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
-
Methods inherited from interface com.vaadin.flow.component.shared.HasClearButton
isClearButtonVisible, setClearButtonVisible
-
Methods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperText
-
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
-
-
-
-
Constructor Detail
-
ComboBox
public ComboBox(int pageSize)
Creates an empty combo box with the defined page size for lazy loading.The default page size is 50.
The page size is also the largest number of items that can support client-side filtering. If you provide more items than the page size, the component has to fall back to server-side filtering.
- Parameters:
pageSize- the amount of items to request at a time for lazy loading
-
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- See Also:
setLabel(String)
-
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 box- See Also:
setLabel(String),setItems(Collection)
-
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 box- See Also:
setLabel(String),HasListDataView.setItems(Object...)
-
ComboBox
public ComboBox(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>> listener)
Constructs a combo box with a value change listener.- Parameters:
listener- the value change listener to add- See Also:
AbstractField.addValueChangeListener(ValueChangeListener)
-
ComboBox
public ComboBox(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>> listener)
Constructs a combo box with the defined label and a value change listener.- Parameters:
label- the label describing the combo boxlistener- the value change listener to add- See Also:
setLabel(String),AbstractField.addValueChangeListener(ValueChangeListener)
-
ComboBox
@SafeVarargs public ComboBox(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>> listener, T... items)
Constructs a combo box with the defined label, a value change listener and populated with the items in the array.- Parameters:
label- the label describing the combo boxlistener- the value change listener to additems- the items to be shown in the list of the combo box- See Also:
setLabel(String),AbstractField.addValueChangeListener(ValueChangeListener),HasListDataView.setItems(Object...)
-
-
Method Detail
-
setValue
public void setValue(T value)
-
setRenderer
public void setRenderer(Renderer<T> renderer)
Sets the Renderer 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 usingsetItemLabelGenerator(ItemLabelGenerator).- Parameters:
renderer- a renderer for the items in the selection list of the ComboBox, notnullNote that filtering of the ComboBox is not affected by the renderer that is set here. Filtering is done on the original values and can be affected bysetItemLabelGenerator(ItemLabelGenerator).
-
setItems
public ComboBoxListDataView<T> setItems(Collection<T> items)
Filtering will use a case insensitive match to show all items where the filter text is a substring of the label displayed for that item, which you can configure with
setItemLabelGenerator(ItemLabelGenerator).Filtering will be handled in the client-side if the size of the data set is less than the page size. To force client-side filtering with a larger data set (at the cost of increased network traffic), you can increase the page size with
setPageSize(int).Setting the items resets the combo box's value to
null.- Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasListDataView<T,ComboBoxListDataView<T>>
-
setItems
public ComboBoxListDataView<T> setItems(ComboBox.ItemFilter<T> itemFilter, Collection<T> items)
Sets the data items of this combo box and a filtering function for defining which items are displayed when user types into the combo box.Note that defining a custom filter will force the component to make server roundtrips to handle the filtering. Otherwise it can handle filtering in the client-side, if the size of the data set is less than the
pageSize.Setting the items resets the combo box's value to
null.The returned data view object can be used for further access to combo box items, or later on fetched with
getListDataView(). For using lazy data loading, use one of thesetItemsmethods which take a fetch callback parameter instead.- Parameters:
itemFilter- filter to check if an item is shown when user typed some text into the ComboBoxitems- the data items to display- Returns:
- the in-memory data view instance that provides access to the data bound to the combo box
-
setItems
public ComboBoxListDataView<T> setItems(ComboBox.ItemFilter<T> itemFilter, T... items)
Sets the data items of this combo box and a filtering function for defining which items are displayed when user types into the combo box.Note that defining a custom filter will force the component to make server roundtrips to handle the filtering. Otherwise it can handle filtering in the client-side, if the size of the data set is less than the
pageSize.Setting the items resets the combo box's value to
null.The returned data view object can be used for further access to combo box items, or later on fetched with
getListDataView(). For using lazy data loading, use one of thesetItemsmethods which take a fetch callback parameter instead.- Parameters:
itemFilter- filter to check if an item is shown when user typed some text into the ComboBoxitems- the data items to display- Returns:
- the in-memory data view instance that provides access to the data bound to the combo box
-
setItems
@Deprecated public void setItems(Stream<T> streamOfItems)
Deprecated.Because the stream is collected to a list anyway, usesetItems(Collection)orsetItems(CallbackDataProvider.FetchCallback)instead.
-
setItems
public ComboBoxDataView<T> setItems(com.vaadin.flow.data.provider.DataProvider<T,String> dataProvider)
- Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasDataView<T,String,ComboBoxDataView<T>>
-
setItems
@Deprecated public ComboBoxDataView<T> setItems(com.vaadin.flow.data.provider.InMemoryDataProvider<T> dataProvider)
Deprecated.does not work so don't useThe method is not supported for theComboBoxcomponent, use another overloaded method with filter convertersetItems(InMemoryDataProvider, SerializableFunction)Always throws an
UnsupportedOperationException.- Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasDataView<T,String,ComboBoxDataView<T>>- Throws:
UnsupportedOperationException- See Also:
setItems(InMemoryDataProvider, SerializableFunction)
-
setItems
public ComboBoxDataView<T> setItems(com.vaadin.flow.data.provider.InMemoryDataProvider<T> inMemoryDataProvider, com.vaadin.flow.function.SerializableFunction<String,com.vaadin.flow.function.SerializablePredicate<T>> filterConverter)
Sets an in-memory data provider for the combo box to use, taking into account both in-memory filtering from data provider and combo box's text filter.Text filter is transformed into a predicate filter through the given filter converter. Example of filter converter which produces the Person's name predicate:
(String nameFilter) -> person -> person.getName().equalsIgnoreCase (nameFilter);Filtering will be handled in the client-side if the size of the data set is less than the page size. To force client-side filtering with a larger data set (at the cost of increased network traffic), you can increase the page size with
setPageSize(int).Note! Using a
ListDataProviderinstead of aInMemoryDataProvideris recommended to get access toListDataViewAPI by usingsetItems(ListDataProvider).- Parameters:
inMemoryDataProvider- InMemoryDataProvider to use, notnullfilterConverter- a function which converts a component's internal filter into a predicate applied to the data provider- Returns:
- DataView providing information on the data
-
getGenericDataView
public ComboBoxDataView<T> getGenericDataView()
Gets the generic data view for the ComboBox. This data view can be used whengetListDataView()orgetLazyDataView()are not applicable for the underlying data provider, or you don't want to distinct between which type of data view to use.- Specified by:
getGenericDataViewin interfacecom.vaadin.flow.data.provider.HasDataView<T,String,ComboBoxDataView<T>>- Returns:
- the generic
DataViewimplementation for ComboBox - See Also:
getListDataView(),getLazyDataView()
-
setItems
public ComboBoxLazyDataView<T> setItems(com.vaadin.flow.data.provider.BackEndDataProvider<T,String> dataProvider)
- Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasLazyDataView<T,String,ComboBoxLazyDataView<T>>
-
getLazyDataView
public ComboBoxLazyDataView<T> getLazyDataView()
Gets the lazy data view for the ComboBox. This data view should only be used when the items are provided lazily from the backend with:setItems(CallbackDataProvider.FetchCallback)setItemsWithFilterConverter(CallbackDataProvider.FetchCallback, SerializableFunction)>setItems(CallbackDataProvider.FetchCallback, CallbackDataProvider.CountCallback)setItemsWithFilterConverter(CallbackDataProvider.FetchCallback, CallbackDataProvider.CountCallback, SerializableFunction)setItems(BackEndDataProvider)
getListDataView()instead.- Specified by:
getLazyDataViewin interfacecom.vaadin.flow.data.provider.HasLazyDataView<T,String,ComboBoxLazyDataView<T>>- Returns:
- the lazy data view that provides access to the data bound to the ComboBox
- Throws:
IllegalStateException- if no items fetch callback(s) set
-
setItems
public ComboBoxListDataView<T> setItems(com.vaadin.flow.data.provider.ListDataProvider<T> dataProvider)
- Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasListDataView<T,ComboBoxListDataView<T>>
-
getListDataView
public ComboBoxListDataView<T> getListDataView()
Gets the list data view for the ComboBox. This data view should only be used when the items are in-memory set with:setItems(Collection)HasListDataView.setItems(Object[])setItems(ListDataProvider)setItems(ItemFilter, ListDataProvider)setItems(ItemFilter, Object[])setItems(ItemFilter, Collection)
getLazyDataView()instead.- Specified by:
getListDataViewin interfacecom.vaadin.flow.data.provider.HasListDataView<T,ComboBoxListDataView<T>>- Returns:
- the list data view that provides access to the items in the ComboBox
-
setDataProvider
@Deprecated public void setDataProvider(com.vaadin.flow.data.provider.DataProvider<T,String> dataProvider)
Deprecated.use instead one of thesetItemsmethods which provide access to eitherComboBoxListDataVieworComboBoxLazyDataViewThe filter-type of the given data provider must be String so that it can handle the filters typed into the ComboBox by users. If your data provider uses some other type of filter, you can provide a function which converts the ComboBox's filter-string into that type via
setDataProvider(DataProvider, SerializableFunction). Another way to do the same thing is to use this method with your data provider converted withDataProvider.withConvertedFilter(SerializableFunction).Changing the combo box's data provider resets its current value to
null.
-
setItemsWithFilterConverter
public <C> ComboBoxLazyDataView<T> setItemsWithFilterConverter(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T,C> fetchCallback, com.vaadin.flow.function.SerializableFunction<String,C> filterConverter)
Supply items lazily with a callback from a backend, using custom filter type. The combo box will automatically fetch more items and adjust its size until the backend runs out of items. Usage example:comboBox.setItemsWithFilterConverter( query -> orderService.getOrdersByCount(query.getFilter(), query.getOffset, query.getLimit()), orderCountStr -> Integer.parseInt(orderCountStr));Note: Validations fororderCountStrare omitted for briefness.Combo box's client-side filter typed by the user is transformed into a callback's filter through the given filter converter.
The returned data view object can be used for further configuration, or later on fetched with
getLazyDataView(). For using in-memory data, likeCollection, usesetItems(Collection)instead.- Type Parameters:
C- filter type used by a callback- Parameters:
fetchCallback- function that returns a stream of items from the backend based on the offset, limit and a object filterfilterConverter- a function which converts a combo box's filter-string typed by the user into a callback's object filter- Returns:
- ComboBoxLazyDataView instance for further configuration
-
setItemsWithFilterConverter
public <C> ComboBoxLazyDataView<T> setItemsWithFilterConverter(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T,C> fetchCallback, com.vaadin.flow.data.provider.CallbackDataProvider.CountCallback<T,C> countCallback, com.vaadin.flow.function.SerializableFunction<String,C> filterConverter)
Supply items lazily with callbacks: the first one fetches the items based on offset, limit and an optional filter, the second provides the exact count of items in the backend. Use this only in case getting the count is cheap and the user benefits from the component showing immediately the exact size. Usage example:comboBox.setItemsWithFilterConverter( query -> orderService.getOrdersByCount(query.getFilter(), query.getOffset, query.getLimit()), query -> orderService.getSize(query.getFilter()), orderCountStr -> Integer.parseInt(orderCountStr));Note: Validations fororderCountStrare omitted for briefness.Combo box's client-side filter typed by the user is transformed into a custom filter type through the given filter converter.
The returned data view object can be used for further configuration, or later on fetched with
getLazyDataView(). For using in-memory data, likeCollection, usesetItems(Collection)instead.- Type Parameters:
C- filter type used by a callbacks- Parameters:
fetchCallback- function that returns a stream of items from the backend based on the offset, limit and a object filterfilterConverter- a function which converts a combo box's filter-string typed by the user into a callback's object filter- Returns:
- ComboBoxLazyDataView instance for further configuration
-
setDataProvider
@Deprecated public <C> void setDataProvider(com.vaadin.flow.data.provider.DataProvider<T,C> dataProvider, com.vaadin.flow.function.SerializableFunction<String,C> filterConverter)
Deprecated.use instead one of thesetItemsmethods which provide access to eitherComboBoxListDataVieworComboBoxLazyDataViewComboBox triggers filtering queries based on the strings users type into the field. For this reason you need to provide the second parameter, a function which converts the filter-string typed by the user into filter-type used by your data provider. If your data provider already supports String as the filter-type, it can be used without a converter function via
setDataProvider(DataProvider).Using this method provides the same result as using a data provider wrapped with
DataProvider.withConvertedFilter(SerializableFunction).Changing the combo box's data provider resets its current value to
null.
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
- Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
onDetach
protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
- Overrides:
onDetachin classcom.vaadin.flow.component.Component
-
setDataProvider
@Deprecated public void setDataProvider(com.vaadin.flow.data.provider.ListDataProvider<T> listDataProvider)
Deprecated.use instead one of thesetItemsmethods which provide access toComboBoxListDataViewSets a list data provider as the data provider of this combo box.Filtering will use a case insensitive match to show all items where the filter text is a substring of the label displayed for that item, which you can configure with
setItemLabelGenerator(ItemLabelGenerator).Filtering will be handled in the client-side if the size of the data set is less than the page size. To force client-side filtering with a larger data set (at the cost of increased network traffic), you can increase the page size with
setPageSize(int).Changing the combo box's data provider resets its current value to
null.- Parameters:
listDataProvider- the list data provider to use, notnull
-
setDataProvider
@Deprecated public void setDataProvider(ComboBox.FetchItemsCallback<T> fetchItems, com.vaadin.flow.function.SerializableFunction<String,Integer> sizeCallback)
Deprecated.use insteadsetItems(CallbackDataProvider.FetchCallback, CallbackDataProvider.CountCallback)which provide access toComboBoxLazyDataViewSets a CallbackDataProvider using the given fetch items callback and a size callback.This method is a shorthand for making a
CallbackDataProviderthat handles a partialQueryobject.Changing the combo box's data provider resets its current value to
null.- Parameters:
fetchItems- a callback for fetching items, notnullsizeCallback- a callback for getting the count of items, notnull- See Also:
CallbackDataProvider,setDataProvider(DataProvider)
-
setDataProvider
@Deprecated public void setDataProvider(ComboBox.ItemFilter<T> itemFilter, com.vaadin.flow.data.provider.ListDataProvider<T> listDataProvider)
Deprecated.use insteadsetItems(ItemFilter, ListDataProvider)which provide access toComboBoxListDataViewSets a list data provider with an item filter as the data provider of this combo box. The item filter is used to compare each item to the filter text entered by the user.Note that defining a custom filter will force the component to make server roundtrips to handle the filtering. Otherwise it can handle filtering in the client-side, if the size of the data set is less than the
pageSize.Changing the combo box's data provider resets its current value to
null.- Parameters:
itemFilter- filter to check if an item is shown when user typed some text into the ComboBoxlistDataProvider- the list data provider to use, notnull
-
setItems
public ComboBoxListDataView<T> setItems(ComboBox.ItemFilter<T> itemFilter, com.vaadin.flow.data.provider.ListDataProvider<T> listDataProvider)
Sets a ListDataProvider for this combo box and a filtering function for defining which items are displayed when user types into the combo box.Note that defining a custom filter will force the component to make server roundtrips to handle the filtering. Otherwise it can handle filtering in the client-side, if the size of the data set is less than the
pageSize.Setting the items resets the combo box's value to
null.The returned data view object can be used for further access to combo box items, or later on fetched with
getListDataView(). For using lazy data loading, use one of thesetItemsmethods which take a fetch callback parameter instead.- Parameters:
itemFilter- filter to check if an item is shown when user typed some text into the ComboBox.listDataProvider- ListDataProvider providing items to the component.- Returns:
- the in-memory data view instance that provides access to the data bound to the combo box
-
getDataProvider
public com.vaadin.flow.data.provider.DataProvider<T,?> getDataProvider()
Gets the data provider used by this ComboBox.- Returns:
- the data provider used by this ComboBox
-
setItemLabelGenerator
public void setItemLabelGenerator(com.vaadin.flow.component.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 com.vaadin.flow.component.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
-
setPageSize
public void setPageSize(int pageSize)
Sets the page size, which is the number of items requested at a time from the data provider. This does not guarantee a maximum query size to the backend; when the overlay has room to render more new items than the page size, multiple "pages" will be requested at once.The page size is also the largest number of items that can support client-side filtering. If you provide more items than the page size, the component has to fall back to server-side filtering.
Setting the page size after the ComboBox has been rendered effectively resets the component, and the current page(s) and sent over again.
The default page size is 50.
- Parameters:
pageSize- the maximum number of items sent per request, should be greater than zero
-
getPageSize
public int getPageSize()
Gets the page size, which is the number of items fetched at a time from the data provider.The page size is also the largest number of items that can support client-side filtering. If you provide more items than the page size, the component has to fall back to server-side filtering.
The default page size is 50.
- Returns:
- the maximum number of items sent per request
-
setOpened
public void setOpened(boolean opened)
Description copied from class:GeneratedVaadinComboBoxDescription copied from corresponding location in WebComponent:
True if the dropdown is open, false otherwise.
- Overrides:
setOpenedin classGeneratedVaadinComboBox<ComboBox<T>,T>- Parameters:
opened- the boolean value to set
-
isOpened
public boolean isOpened()
Gets the states of the drop-down.- Returns:
trueif the drop-down is opened,falseotherwise
-
setInvalid
public void setInvalid(boolean invalid)
Description copied from class:GeneratedVaadinComboBoxDescription copied from corresponding location in WebComponent:
Set to true if the value is invalid.
- Specified by:
setInvalidin interfacecom.vaadin.flow.component.HasValidation- Overrides:
setInvalidin 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:
isInvalidin interfacecom.vaadin.flow.component.HasValidation- Returns:
- the
validityproperty from the component
-
setErrorMessage
public void setErrorMessage(String errorMessage)
Description copied from class:GeneratedVaadinComboBoxDescription copied from corresponding location in WebComponent:
The error message to display when the input is invalid.
- Specified by:
setErrorMessagein interfacecom.vaadin.flow.component.HasValidation- Overrides:
setErrorMessagein 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:
getErrorMessagein interfacecom.vaadin.flow.component.HasValidation- Returns:
- the current error message
-
setAllowCustomValue
public void setAllowCustomValue(boolean allowCustomValue)
Enables or disables the component firing events for custom string input.When enabled, a
GeneratedVaadinComboBox.CustomValueSetEventwill be fired when the user inputs a string value that does not match any existing items and commits it eg. by blurring or pressing the enter-key.Note that ComboBox doesn't do anything with the custom value string automatically. Use the
addCustomValueSetListener(ComponentEventListener)method to determine how the custom value should be handled. For example, when the ComboBox hasStringas the value type, you can add a listener which sets the custom string as the value of the ComboBox withsetValue(Object).Setting to
truealso allows an unfocused ComboBox to display a string that doesn't match any of its items nor its current value, unless this is explicitly handled withaddCustomValueSetListener(ComponentEventListener). When set tofalse, an unfocused ComboBox will always display the label of the currently selected item.- Overrides:
setAllowCustomValuein classGeneratedVaadinComboBox<ComboBox<T>,T>- Parameters:
allowCustomValue-trueto enable custom value set events,falseto disable them- See Also:
addCustomValueSetListener(ComponentEventListener)
-
isAllowCustomValue
public boolean isAllowCustomValue()
Iftrue, the user can input string values that do not match to any existing item labels, which will fire aGeneratedVaadinComboBox.CustomValueSetEvent.- Returns:
trueif the component fires custom value set events,falseotherwise- See Also:
setAllowCustomValue(boolean),addCustomValueSetListener(ComponentEventListener)
-
setAutoOpen
public void setAutoOpen(boolean autoOpen)
Enables or disables the dropdown opening automatically. Iffalsethe dropdown is only opened when clicking the toggle button or pressing Up or Down arrow keys.- Parameters:
autoOpen-falseto prevent the dropdown from opening automatically
-
isAutoOpen
public boolean isAutoOpen()
Gets whether dropdown will open automatically or not.- Returns:
-
setAutofocus
public void setAutofocus(boolean autofocus)
Set the combobox to be input focused when the page loads.- Overrides:
setAutofocusin 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
autofocusproperty from the combobox
-
setPreventInvalidInput
public void setPreventInvalidInput(boolean preventInvalidInput)
Description copied from class:GeneratedVaadinComboBoxDescription copied from corresponding location in WebComponent:
Set to true to prevent the user from entering invalid input.
- Overrides:
setPreventInvalidInputin 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
preventInvalidInputproperty of the combobox
-
setRequired
public void setRequired(boolean required)
Description copied from class:GeneratedVaadinComboBoxDescription copied from corresponding location in WebComponent:
Set to true to mark the input as required.
- Overrides:
setRequiredin 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:
trueif the input is required,falseotherwise
-
setLabel
public void setLabel(String label)
Sets the label for the combobox.- Specified by:
setLabelin interfacecom.vaadin.flow.component.HasLabel- Overrides:
setLabelin classGeneratedVaadinComboBox<ComboBox<T>,T>- Parameters:
label- value for thelabelproperty in the combobox
-
getLabel
public String getLabel()
Gets the label of the combobox.- Specified by:
getLabelin interfacecom.vaadin.flow.component.HasLabel- Returns:
- the
labelproperty of the combobox
-
setPlaceholder
public void setPlaceholder(String placeholder)
Description copied from class:GeneratedVaadinComboBoxDescription copied from corresponding location in WebComponent:
A placeholder string in addition to the label.
- Overrides:
setPlaceholderin classGeneratedVaadinComboBox<ComboBox<T>,T>- Parameters:
placeholder- the String value to set
-
getPlaceholder
public String getPlaceholder()
Gets the placeholder of the combobox.- Returns:
- the
placeholderproperty of the combobox
-
setPattern
public void setPattern(String pattern)
Description copied from class:GeneratedVaadinComboBoxDescription copied from corresponding location in WebComponent:
A pattern to validate the
inputwith.- Overrides:
setPatternin classGeneratedVaadinComboBox<ComboBox<T>,T>- Parameters:
pattern- the String value to set
-
getPattern
public String getPattern()
Gets the valid input pattern- Returns:
- the
patternproperty of the combobox
-
getEmptyValue
public T getEmptyValue()
-
addCustomValueSetListener
public com.vaadin.flow.shared.Registration addCustomValueSetListener(com.vaadin.flow.component.ComponentEventListener<GeneratedVaadinComboBox.CustomValueSetEvent<ComboBox<T>>> listener)
Adds a listener for the event which is fired when user inputs a string value that does not match any existing items and commits it eg. by blurring or pressing the enter-key.Note that ComboBox doesn't do anything with the custom value string automatically. Use this method to determine how the custom value should be handled. For example, when the ComboBox has
Stringas the value type, you can add a listener which sets the custom string as the value of the ComboBox withsetValue(Object).As a side effect, this makes the ComboBox allow custom values. If you want to disable the firing of custom value set events 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:
addCustomValueSetListenerin classGeneratedVaadinComboBox<ComboBox<T>,T>- Parameters:
listener- the listener to be notified when a new value is filled- Returns:
- a
Registrationfor removing the event listener - See Also:
setAllowCustomValue(boolean)
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
- Specified by:
setRequiredIndicatorVisiblein interfacecom.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>,T>- Specified by:
setRequiredIndicatorVisiblein interfacecom.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>,T>
-
setItems
public ComboBoxLazyDataView<T> setItems(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T,String> fetchCallback)
Supply items lazily with a callback from a backend. The ComboBox will automatically fetch more items and adjust its size until the backend runs out of items. Usage example without component provided filter:comboBox.setItems(query -> orderService.getOrders(query.getOffset(), query.getLimit());Since ComboBox supports filtering, it can be fetched via query.getFilter():
comboBox.setItems(query -> orderService.getOrders(query.getFilter(), query.getOffset(), query.getLimit());The returned data view object can be used for further configuration, or later on fetched with
getLazyDataView(). For using in-memory data, likeCollection, useHasListDataView.setItems(Collection)instead.If item filtering by some value type other than String is preferred and backend service is able to fetch and filter items by such type, converter for client side's filter string can be set along with fetch callback. See:
setItemsWithFilterConverter(CallbackDataProvider.FetchCallback, SerializableFunction)- Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasLazyDataView<T,String,ComboBoxLazyDataView<T>>- Parameters:
fetchCallback- function that returns a stream of items from the backend based on the offset, limit and an optional filter provided by the query object- Returns:
- ComboBoxLazyDataView instance for further configuration
-
setItems
public ComboBoxLazyDataView<T> setItems(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T,String> fetchCallback, com.vaadin.flow.data.provider.CallbackDataProvider.CountCallback<T,String> countCallback)
Supply items lazily with callbacks: the first one fetches the items based on offset, limit and an optional filter, the second provides the exact count of items in the backend. Use this only in case getting the count is cheap and the user benefits from the ComboBox showing immediately the exact size. Usage example without component provided filter:comboBox.setItems( query -> orderService.getOrders(query.getOffset, query.getLimit()), query -> orderService.getSize());Since ComboBox supports filtering, it can be fetched via query.getFilter():
comboBox.setItems( query -> orderService.getOrders(query.getFilter(), query.getOffset, query.getLimit()), query -> orderService.getSize(query.getFilter()));The returned data view object can be used for further configuration, or later on fetched with
getLazyDataView(). For using in-memory data, likeCollection, useHasListDataView.setItems(Collection)instead.If item filtering by some value type other than String is preferred and backend service is able to fetch and filter items by such type, converter for client side's filter string can be set along with fetch callback. See:
setItemsWithFilterConverter(CallbackDataProvider.FetchCallback, CallbackDataProvider.CountCallback, SerializableFunction)- Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasLazyDataView<T,String,ComboBoxLazyDataView<T>>- Parameters:
fetchCallback- function that returns a stream of items from the back end for a querycountCallback- function that return the number of items in the back end for a query- Returns:
- ComboBoxLazyDataView instance for further configuration
-
addThemeVariants
public void addThemeVariants(ComboBoxVariant... variants)
Adds theme variants to the component.- Parameters:
variants- theme variants to add
-
removeThemeVariants
public void removeThemeVariants(ComboBoxVariant... variants)
Removes theme variants from the component.- Parameters:
variants- theme variants to remove
-
-