Class ComboBoxBase<TComponent extends ComboBoxBase<TComponent,TItem,TValue>,TItem,TValue>
- Type Parameters:
TComponent- Type of the component that extends from this classTItem- Type of individual items that are selectable in the combo boxTValue- Type of the selection / value of the extending component
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.BlurNotifier<TComponent>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<TComponent>,com.vaadin.flow.component.FocusNotifier<TComponent>,com.vaadin.flow.component.HasAriaLabel,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasHelper,com.vaadin.flow.component.HasLabel,com.vaadin.flow.component.HasPlaceholder,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<TComponent,,TValue>, TValue> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TComponent,,TValue>, TValue> HasAllowedCharPattern,HasAutoOpen,HasClearButton,HasClientValidation,HasOverlayClassName,HasTooltip,HasValidationProperties,InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TComponent,,TValue>, TValue> com.vaadin.flow.data.binder.HasValidator<TValue>,com.vaadin.flow.data.provider.HasDataView<TItem,,String, ComboBoxDataView<TItem>> com.vaadin.flow.data.provider.HasLazyDataView<TItem,,String, ComboBoxLazyDataView<TItem>> com.vaadin.flow.data.provider.HasListDataView<TItem,,ComboBoxListDataView<TItem>> Serializable
- Direct Known Subclasses:
ComboBox,MultiSelectComboBox
ComboBox- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classComboBoxBase.CustomValueSetEvent<TComponent extends ComboBoxBase<TComponent,?, ?>> Event that is dispatched from a combo box component, if the component allows setting custom values, and the user has entered a non-empty value that does not match any of the existing itemsNested 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.shared.HasClientValidation
HasClientValidation.ClientValidatedEventNested 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
ConstructorsConstructorDescriptionComboBoxBase(String valuePropertyName, TValue defaultValue, Class<TValueProperty> valuePropertyType, com.vaadin.flow.function.SerializableBiFunction<TComponent, TValueProperty, TValue> presentationToModel, com.vaadin.flow.function.SerializableBiFunction<TComponent, TValue, TValueProperty> modelToPresentation) Constructs a new ComboBoxBase instance -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationaddCustomValueSetListener(com.vaadin.flow.component.ComponentEventListener<ComboBoxBase.CustomValueSetEvent<TComponent>> 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.protected StringgenerateClassName(TItem item) Generates a string class name for a data item using the current item class name generatorprotected StringgenerateLabel(TItem item) Generates a string label for a data item using the current item label generatorprotected ComboBoxDataCommunicator<TItem>Accesses the data communicator that is managed by the data controllerprotected com.vaadin.flow.component.combobox.ComboBoxDataController<TItem>Accesses the data controller that is managing data communication with the web componentprotected com.vaadin.flow.data.provider.CompositeDataGenerator<TItem>Accesses the data generator that is managed by the data controllercom.vaadin.flow.data.provider.DataProvider<TItem,?> Gets the data provider used by this ComboBox.com.vaadin.flow.data.binder.Validator<TValue>protected StringFiltering string the user has typed into the input field.Gets the generic data view for the ComboBox.protected ComboBoxBaseI18ngetI18n()Gets the internationalization object previously set for this component.Gets the item class name generator that is used for generating CSS class names for the dropdown items in the ComboBox.com.vaadin.flow.component.ItemLabelGenerator<TItem>Gets the item label generator that is used to produce the strings shown in the combo box for each item.protected com.vaadin.flow.data.provider.DataKeyMapper<TItem>Accesses the key mapper that is managed by the data controllerGets the lazy data view for the ComboBox.Gets the list data view for the ComboBox.intGets the page size, which is the number of items fetched at a time from the data provider.protected com.vaadin.flow.component.combobox.ComboBoxRenderManager<TItem>Accesses the render manager that is managing the custom rendererbooleanIftrue, the user can input string values that do not match to any existing item labels, which will fire aComboBoxBase.CustomValueSetEvent.booleanWhether the component should automatically receive focus when the page loads.booleanisOpened()Whether the dropdown is opened or not.booleanAlias forisRequiredIndicatorVisible()booleanGets whether the user is required to provide a value.protected abstract booleanisSelected(TItem item) Whether the item is currently selected in the combo box.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) protected voidonDetach(com.vaadin.flow.component.DetachEvent detachEvent) protected abstract voidRefresh value / selection of the web component after changes that might affect the presentation / rendering of itemsprotected voidrunBeforeClientResponse(com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.component.UI> command) Helper for running a command in the before client response hookvoidsetAllowCustomValue(boolean allowCustomValue) Enables or disables the component firing events for custom string input.voidsetAriaLabel(String ariaLabel) voidsetAriaLabelledBy(String labelledBy) voidsetAutofocus(boolean autofocus) Sets the whether the component should automatically receive focus when the page loads.voidsetClassNameGenerator(com.vaadin.flow.function.SerializableFunction<TItem, String> classNameGenerator) Sets the function that is used for generating CSS class names for the dropdown items in the ComboBox.voidsetDataProvider(ComboBox.FetchItemsCallback<TItem> fetchItems, com.vaadin.flow.function.SerializableFunction<String, Integer> sizeCallback) Sets a CallbackDataProvider using the given fetch items callback and a size callback.<C> voidsetDataProvider(com.vaadin.flow.data.provider.DataProvider<TItem, C> dataProvider, com.vaadin.flow.function.SerializableFunction<String, C> filterConverter) Sets a generic data provider for the ComboBox to use.protected voidSets the filter string for the filter input.protected voidsetI18n(ComboBoxBaseI18n i18n) Sets the internationalization object for this component.voidsetItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<TItem> itemLabelGenerator) Sets the item label generator that is used to produce the strings shown in the combo box for each item.setItems(ComboBox.ItemFilter<TItem> itemFilter, com.vaadin.flow.data.provider.ListDataProvider<TItem> 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.setItems(ComboBox.ItemFilter<TItem> itemFilter, Collection<TItem> 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.setItems(ComboBox.ItemFilter<TItem> itemFilter, TItem... 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.setItems(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<TItem, String> fetchCallback) Supply items lazily with a callback from a backend.setItems(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<TItem, String> fetchCallback, com.vaadin.flow.data.provider.CallbackDataProvider.CountCallback<TItem, 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.Deprecated.does not work so don't usesetItems(com.vaadin.flow.data.provider.InMemoryDataProvider<TItem> inMemoryDataProvider, com.vaadin.flow.function.SerializableFunction<String, com.vaadin.flow.function.SerializablePredicate<TItem>> 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.setItems(Collection<TItem> items) setItemsWithFilterConverter(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<TItem, C> fetchCallback, com.vaadin.flow.data.provider.CallbackDataProvider.CountCallback<TItem, 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.setItemsWithFilterConverter(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<TItem, C> fetchCallback, com.vaadin.flow.function.SerializableFunction<String, C> filterConverter) Supply items lazily with a callback from a backend, using custom filter type.voidsetManualValidation(boolean enabled) voidsetOpened(boolean opened) Sets whether the dropdown should be opened or not.voidsetPageSize(int pageSize) Sets the page size, which is the number of items requested at a time from the data provider.voidsetRenderer(Renderer<TItem> renderer) Sets the Renderer responsible to render the individual items in the list of possible choices of the ComboBox.voidsetRequired(boolean required) Alias forsetRequiredIndicatorVisible(boolean).voidsetRequiredIndicatorVisible(boolean required) Sets whether the user is required to provide a value.voidprotected voidvalidate()Validates the current value against the constraints and sets theinvalidproperty and theerrorMessageproperty based on the result.Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEventMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.shared.HasAllowedCharPattern
getAllowedCharPattern, setAllowedCharPatternMethods inherited from interface com.vaadin.flow.component.shared.HasAutoOpen
isAutoOpen, setAutoOpenMethods inherited from interface com.vaadin.flow.component.shared.HasClearButton
isClearButtonVisible, setClearButtonVisibleMethods inherited from interface com.vaadin.flow.component.shared.HasClientValidation
addClientValidatedEventListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface com.vaadin.flow.component.HasLabel
getLabel, setLabelMethods inherited from interface com.vaadin.flow.data.provider.HasListDataView
setItemsMethods inherited from interface com.vaadin.flow.component.shared.HasOverlayClassName
getOverlayClassName, setOverlayClassNameMethods inherited from interface com.vaadin.flow.component.HasPlaceholder
getPlaceholder, setPlaceholderMethods 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, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipTextMethods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalidMethods inherited from interface com.vaadin.flow.data.binder.HasValidator
addValidationStatusChangeListenerMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmptyMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, setReadOnly
-
Constructor Details
-
ComboBoxBase
public ComboBoxBase(String valuePropertyName, TValue defaultValue, Class<TValueProperty> valuePropertyType, com.vaadin.flow.function.SerializableBiFunction<TComponent, TValueProperty, TValue> presentationToModel, com.vaadin.flow.function.SerializableBiFunction<TComponent, TValue, TValueProperty> modelToPresentation) Constructs a new ComboBoxBase instance- Type Parameters:
TValueProperty- the type of the raw value of the Flow element property- Parameters:
valuePropertyName- name of the value property of the web component that should be used to set values, or listen to value changesdefaultValue- the default value of the componentvaluePropertyType- the class that represents the type of the raw value of the Flow element propertypresentationToModel- a function to convert a raw property value into a value using the user-specified model typemodelToPresentation- a function to convert a value using the user-specified model type into a raw property value
-
-
Method Details
-
isAutofocus
public boolean isAutofocus()Whether the component should automatically receive focus when the page loads.- Returns:
trueif the component should automatically receive focus
-
setAutofocus
public void setAutofocus(boolean autofocus) Sets the whether the component should automatically receive focus when the page loads. Defaults tofalse.- Parameters:
autofocus-truecomponent should automatically receive focus
-
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
- See Also:
-
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
-
isOpened
@Synchronize(property="opened", value="opened-changed") public boolean isOpened()Whether the dropdown is opened or not.- Returns:
trueif the drop-down is opened,falseotherwise
-
setOpened
public void setOpened(boolean opened) Sets whether the dropdown should be opened or not.- Parameters:
opened-trueto open the drop-down,falseto close it
-
isAllowCustomValue
public boolean isAllowCustomValue()Iftrue, the user can input string values that do not match to any existing item labels, which will fire aComboBoxBase.CustomValueSetEvent.- Returns:
trueif the component fires custom value set events,falseotherwise- See Also:
-
setAllowCustomValue
public void setAllowCustomValue(boolean allowCustomValue) Enables or disables the component firing events for custom string input.When enabled, a
ComboBoxBase.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.- Parameters:
allowCustomValue-trueto enable custom value set events,falseto disable them- See Also:
-
getFilter
Filtering string the user has typed into the input field.- Returns:
- the filter string
-
setFilter
Sets the filter string for the filter input.Setter is only required to allow using @Synchronize
- Parameters:
filter- the String value to set
-
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
HasLabel.setLabel(String).- Specified by:
setRequiredIndicatorVisiblein interfacecom.vaadin.flow.component.HasValue<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem> - Specified by:
setRequiredIndicatorVisiblein interfacecom.vaadin.flow.component.HasValueAndElement<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem> - Parameters:
required-trueto make the field required,falseotherwise
-
isRequiredIndicatorVisible
public boolean isRequiredIndicatorVisible()Gets whether the user is required to provide a value.- Specified by:
isRequiredIndicatorVisiblein interfacecom.vaadin.flow.component.HasValue<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem> - Specified by:
isRequiredIndicatorVisiblein interfacecom.vaadin.flow.component.HasValueAndElement<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem> - Returns:
trueif the field is required,falseotherwise- See Also:
-
isRequired
public boolean isRequired()Alias forisRequiredIndicatorVisible()- Returns:
trueif the field is required,falseotherwise
-
setRequired
public void setRequired(boolean required) Alias forsetRequiredIndicatorVisible(boolean).- Parameters:
required-trueto make the field required,falseotherwise
-
setAriaLabel
- Specified by:
setAriaLabelin interfacecom.vaadin.flow.component.HasAriaLabel
-
getAriaLabel
- Specified by:
getAriaLabelin interfacecom.vaadin.flow.component.HasAriaLabel
-
setAriaLabelledBy
- Specified by:
setAriaLabelledByin interfacecom.vaadin.flow.component.HasAriaLabel
-
getAriaLabelledBy
- Specified by:
getAriaLabelledByin interfacecom.vaadin.flow.component.HasAriaLabel
-
setItemLabelGenerator
public void setItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<TItem> 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
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
-
generateLabel
Generates a string label for a data item using the current item label generator- Parameters:
item- the data item- Returns:
- string label for the data item
-
setClassNameGenerator
public void setClassNameGenerator(com.vaadin.flow.function.SerializableFunction<TItem, String> classNameGenerator) Sets the function that is used for generating CSS class names for the dropdown items in the ComboBox. Returningnullfrom the generator results in no custom class name being set. Multiple class names can be returned from the generator as space-separated.- Parameters:
classNameGenerator- the class name generator to set, notnull- Throws:
NullPointerException- ifclassNameGeneratorisnull- Since:
- 24.5
-
getItemClassNameGenerator
Gets the item class name generator that is used for generating CSS class names for the dropdown items in the ComboBox.- Returns:
- the item class name generator, not null
- Since:
- 24.5
-
generateClassName
Generates a string class name for a data item using the current item class name generator- Parameters:
item- the data item- Returns:
- string class name for the data item
-
setRenderer
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 by
setItemLabelGenerator(ItemLabelGenerator).
-
setValue
- Specified by:
setValuein interfacecom.vaadin.flow.component.HasValue<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem> - Overrides:
setValuein classcom.vaadin.flow.component.AbstractField<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TValue>
-
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
-
addCustomValueSetListener
public com.vaadin.flow.shared.Registration addCustomValueSetListener(com.vaadin.flow.component.ComponentEventListener<ComboBoxBase.CustomValueSetEvent<TComponent>> 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.
- Parameters:
listener- the listener to be notified when a new value is filled- Returns:
- a
Registrationfor removing the event listener - See Also:
-
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(ComboBox.ItemFilter, ListDataProvider)setItems(ComboBox.ItemFilter, Object[])setItems(ComboBox.ItemFilter, Collection)
getLazyDataView()instead.- Specified by:
getListDataViewin interfacecom.vaadin.flow.data.provider.HasListDataView<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem> - Returns:
- the list data view that provides access to the items in the ComboBox
-
setItems
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<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem>
-
setItems
public ComboBoxListDataView<TItem> setItems(ComboBox.ItemFilter<TItem> itemFilter, Collection<TItem> 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
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<TItem> setItems(ComboBox.ItemFilter<TItem> itemFilter, com.vaadin.flow.data.provider.ListDataProvider<TItem> 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
-
setItems
public ComboBoxListDataView<TItem> setItems(com.vaadin.flow.data.provider.ListDataProvider<TItem> dataProvider) - Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasListDataView<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem>
-
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<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem, TValue> - Returns:
- the lazy data view that provides access to the data bound to the ComboBox
- Throws:
IllegalStateException- if no items fetch callback(s) set
-
setItemsWithFilterConverter
public <C> ComboBoxLazyDataView<TItem> setItemsWithFilterConverter(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<TItem, 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<TItem> setItemsWithFilterConverter(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<TItem, C> fetchCallback, com.vaadin.flow.data.provider.CallbackDataProvider.CountCallback<TItem, 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 filtercountCallback- function that return the number of items in the back end for a queryfilterConverter- 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
-
setItems
public ComboBoxLazyDataView<TItem> setItems(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<TItem, 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<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem, TValue> - 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<TItem> setItems(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<TItem, String> fetchCallback, com.vaadin.flow.data.provider.CallbackDataProvider.CountCallback<TItem, 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<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem, TValue> - 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
-
setItems
public ComboBoxLazyDataView<TItem> setItems(com.vaadin.flow.data.provider.BackEndDataProvider<TItem, String> dataProvider) - Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasLazyDataView<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem, TValue>
-
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<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem, TValue> - Returns:
- the generic
DataViewimplementation for ComboBox - See Also:
-
setItems
public ComboBoxDataView<TItem> setItems(com.vaadin.flow.data.provider.DataProvider<TItem, String> dataProvider) - Specified by:
setItemsin interfacecom.vaadin.flow.data.provider.HasDataView<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem, TValue>
-
setItems
@Deprecated public ComboBoxDataView<TItem> setItems(com.vaadin.flow.data.provider.InMemoryDataProvider<TItem> 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<TComponent extends ComboBoxBase<TComponent,TItem, TValue>, TItem, TValue> - Throws:
UnsupportedOperationException- when using this method with anInMemoryDataProvider- See Also:
-
setItems
public ComboBoxDataView<TItem> setItems(com.vaadin.flow.data.provider.InMemoryDataProvider<TItem> inMemoryDataProvider, com.vaadin.flow.function.SerializableFunction<String, com.vaadin.flow.function.SerializablePredicate<TItem>> 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
-
setDataProvider
public <C> void setDataProvider(com.vaadin.flow.data.provider.DataProvider<TItem, C> dataProvider, com.vaadin.flow.function.SerializableFunction<String, C> filterConverter) Sets a generic data provider for the ComboBox to use.ComboBox 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
setItems(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.Use this method when none of the
setItemsmethods are applicable, e.g. when having a data provider with filter that cannot be transformed toDataProvider<T, Void>. -
setDataProvider
public void setDataProvider(ComboBox.FetchItemsCallback<TItem> fetchItems, com.vaadin.flow.function.SerializableFunction<String, Integer> sizeCallback) Sets 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
-
getDataProvider
Gets the data provider used by this ComboBox.To get information and control over the items in the ComboBox, use either
getListDataView()orgetLazyDataView()instead.- Returns:
- the data provider used by this ComboBox
-
isSelected
Whether the item is currently selected in the combo box.- Parameters:
item- the item to check- Returns:
trueif the item is selected,falseotherwise
-
refreshValue
protected abstract void refreshValue()Refresh value / selection of the web component after changes that might affect the presentation / rendering of items -
getRenderManager
Accesses the render manager that is managing the custom renderer- Returns:
- the render manager
-
getDataController
Accesses the data controller that is managing data communication with the web componentCan be null if the constructor has not run yet
- Returns:
- the data controller
-
getDataCommunicator
Accesses the data communicator that is managed by the data controllerCan be null if the no data source has been set yet, or if the constructor has not run yet
- Returns:
- the data communicator
-
getDataGenerator
Accesses the data generator that is managed by the data controllerCan be null if the constructor has not run yet
- Returns:
- the data generator
-
getKeyMapper
Accesses the key mapper that is managed by the data controllerCan be null if the no data source has been set yet, or if the constructor has not run yet
- Returns:
- the key mapper
-
runBeforeClientResponse
protected void runBeforeClientResponse(com.vaadin.flow.function.SerializableConsumer<com.vaadin.flow.component.UI> command) Helper for running a command in the before client response hook- Parameters:
command- the command to execute
-
setManualValidation
public void setManualValidation(boolean enabled) - Specified by:
setManualValidationin interfacecom.vaadin.flow.component.HasValidation
-
getDefaultValidator
- Specified by:
getDefaultValidatorin interfacecom.vaadin.flow.data.binder.HasValidator<TComponent extends ComboBoxBase<TComponent,TItem, TValue>>
-
validate
protected void validate()Validates the current value against the constraints and sets theinvalidproperty and theerrorMessageproperty 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.
-
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(ComboBoxBaseI18n)- Returns:
- the i18n object or
nullif no i18n object has been set
-
setI18n
Sets the internationalization object for this component.- Parameters:
i18n- the i18n object, notnull
-