com.vaadin.flow.component.combobox.
Class ComboBoxBase<TComponent extends ComboBoxBase<TComponent,TItem,TValue>,TItem,TValue>
Type Parameters:
TComponent
- Type of the component that extends from this class
TItem
- Type of individual items that are selectable in the combo box
TValue
- Type of the selection / value of the extending component
All Implemented Interfaces:
AttachNotifier
, BlurNotifier<TComponent>
, DetachNotifier
, Focusable<TComponent>
, FocusNotifier<TComponent>
, HasElement
, HasEnabled
, HasHelper
, HasLabel
, HasSize
, HasStyle
, HasTheme
, HasValidation
, HasValue<AbstractField.ComponentValueChangeEvent<TComponent,
, HasValueAndElement<AbstractField.ComponentValueChangeEvent<TComponent,
, HasAllowedCharPattern
, HasAutoOpen
, HasClearButton
, HasClientValidation
, HasOverlayClassName
, HasTooltip
, HasValidationProperties
, HasValidator<TValue>
, HasDataView<TItem,
, HasLazyDataView<TItem,
, HasListDataView<TItem,
, Serializable
Direct Known Subclasses:
Provides base functionality for combo box related components, such as
ComboBox
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
ComboBoxBase.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 items
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
AbstractField.ComponentValueChangeEvent<C extends Component,
V> Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier
BlurNotifier.BlurEvent<C extends Component>
Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
FocusNotifier.FocusEvent<C extends Component>
Nested classes/interfaces inherited from interface com.vaadin.flow.component.shared.HasClientValidation
HasClientValidation.ClientValidatedEvent
Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
-
Constructor Summary
ConstructorsConstructorDescriptionComboBoxBase
(String valuePropertyName, TValue defaultValue, Class<TValueProperty> valuePropertyType, SerializableBiFunction<TComponent, TValueProperty, TValue> presentationToModel, SerializableBiFunction<TComponent, TValue, TValueProperty> modelToPresentation) Constructs a new ComboBoxBase instance
-
Method Summary
Modifier and TypeMethodDescriptionaddCustomValueSetListener
(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.
Enables the implementing components to notify changes in their validation status to the observers.
protected String
generateLabel
(TItem item) Generates a string label for a data item using the current item label generator
protected ComboBoxDataCommunicator<TItem>
Accesses the data communicator that is managed by the data controller
protected com.vaadin.flow.component.combobox.ComboBoxDataController<TItem>
Accesses the data controller that is managing data communication with the web component
protected CompositeDataGenerator<TItem>
Accesses the data generator that is managed by the data controller
Gets the data provider used by this ComboBox.
protected String
Filtering string the user has typed into the input field.
Gets the generic data view for the ComboBox.
Gets the item label generator that is used to produce the strings shown in the combo box for each item.
protected DataKeyMapper<TItem>
Accesses the key mapper that is managed by the data controller
Gets the lazy data view for the ComboBox.
Gets the list data view for the ComboBox.
int
Gets the page size, which is the number of items fetched at a time from the data provider.
The placeholder text that should be displayed in the input element, when the user has not entered a value
protected com.vaadin.flow.component.combobox.ComboBoxRenderManager<TItem>
Accesses the render manager that is managing the custom renderer
boolean
If
true
, the user can input string values that do not match to any existing item labels, which will fire aComboBoxBase.CustomValueSetEvent
.boolean
Whether the component should automatically receive focus when the page loads.
boolean
isOpened()
Whether the dropdown is opened or not.
boolean
Sets whether the component requires a value to be considered in a valid state.
protected abstract boolean
isSelected
(TItem item) Whether the item is currently selected in the combo box.
protected void
onAttach
(AttachEvent attachEvent) Called when the component is attached to a UI.
protected void
onDetach
(DetachEvent detachEvent) Called when the component is detached from a UI.
protected abstract void
Refresh value / selection of the web component after changes that might affect the presentation / rendering of items
protected void
runBeforeClientResponse
(SerializableConsumer<UI> command) Helper for running a command in the before client response hook
void
setAllowCustomValue
(boolean allowCustomValue) Enables or disables the component firing events for custom string input.
void
setAutofocus
(boolean autofocus) Sets the whether the component should automatically receive focus when the page loads.
protected void
Sets the filter string for the filter input.
void
setItemLabelGenerator
(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, 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
(BackEndDataProvider<TItem, String> dataProvider) Supply items with a
BackEndDataProvider
that lazy loads items from a backend.setItems
(CallbackDataProvider.FetchCallback<TItem, String> fetchCallback) Supply items lazily with a callback from a backend.
setItems
(CallbackDataProvider.FetchCallback<TItem, String> fetchCallback, 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.
setItems
(DataProvider<TItem, String> dataProvider) Set a generic data provider for the component to use and returns the base
DataView
that provides API to get information on the items.setItems
(InMemoryDataProvider<TItem> dataProvider) Deprecated.
does not work so don't usesetItems
(InMemoryDataProvider<TItem> inMemoryDataProvider, SerializableFunction<String, 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
(ListDataProvider<TItem> dataProvider) Sets a ListDataProvider for the component to use and returns a
ListDataView
that provides information and allows operations on the items.setItems
(Collection<TItem> items) Sets the items from the given Collection and returns a
ListDataView
that provides information and allows operations on the items.setItemsWithFilterConverter
(CallbackDataProvider.FetchCallback<TItem, C> fetchCallback, CallbackDataProvider.CountCallback<TItem, C> countCallback, 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
(CallbackDataProvider.FetchCallback<TItem, C> fetchCallback, SerializableFunction<String, C> filterConverter) Supply items lazily with a callback from a backend, using custom filter type.
void
setOpened
(boolean opened) Sets whether the dropdown should be opened or not.
void
setPageSize
(int pageSize) Sets the page size, which is the number of items requested at a time from the data provider.
void
setPlaceholder
(String placeholder) Sets the placeholder text that should be displayed in the input element, when the user has not entered a value
void
setRenderer
(Renderer<TItem> renderer) Sets the Renderer responsible to render the individual items in the list of possible choices of the ComboBox.
void
setRequired
(boolean required) Whether the component requires a value to be considered in a valid state.
void
Sets the value of this object.
protected void
validate()
Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent
Methods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, valueEquals
Methods 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, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
Methods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListener
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
Methods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListener
Methods inherited from interface com.vaadin.flow.component.shared.HasAllowedCharPattern
getAllowedCharPattern, setAllowedCharPattern
Methods inherited from interface com.vaadin.flow.component.shared.HasAutoOpen
isAutoOpen, setAutoOpen
Methods inherited from interface com.vaadin.flow.component.shared.HasClearButton
isClearButtonVisible, setClearButtonVisible
Methods inherited from interface com.vaadin.flow.component.shared.HasClientValidation
addClientValidatedEventListener
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
Methods inherited from interface com.vaadin.flow.component.HasEnabled
isEnabled, setEnabled
Methods inherited from interface com.vaadin.flow.component.HasHelper
getHelperComponent, getHelperText, setHelperComponent, setHelperText
Methods inherited from interface com.vaadin.flow.data.provider.HasListDataView
setItems
Methods inherited from interface com.vaadin.flow.component.shared.HasOverlayClassName
getOverlayClassName, setOverlayClassName
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipText
Methods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalid
Methods inherited from interface com.vaadin.flow.data.binder.HasValidator
getDefaultValidator
Methods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValue
Methods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
-
Constructor Details
-
ComboBoxBase
public ComboBoxBase(String valuePropertyName, TValue defaultValue, Class<TValueProperty> valuePropertyType, SerializableBiFunction<TComponent, TValueProperty, TValue> presentationToModel, SerializableBiFunction<TComponent, TValue, TValueProperty> modelToPresentation) Constructs a new ComboBoxBase instance
Type Parameters:
TValueProperty
- the type of the raw value of the Flow element propertyParameters:
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:
true
if 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 to
false
.Parameters:
autofocus
-true
component 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
Whether the dropdown is opened or not.
Returns:
true
if the drop-down is opened,false
otherwise -
setOpened
public void setOpened(boolean opened) Sets whether the dropdown should be opened or not.
Parameters:
opened
-true
to open the drop-down,false
to close it -
isAllowCustomValue
public boolean isAllowCustomValue()If
true
, the user can input string values that do not match to any existing item labels, which will fire aComboBoxBase.CustomValueSetEvent
.Returns:
true
if the component fires custom value set events,false
otherwiseSee Also:
-
setAllowCustomValue
public void setAllowCustomValue(boolean allowCustomValue) Enables or disables the component firing events for custom string input.
When enabled, a
ComboBoxBase.CustomValueSetEvent
will 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 hasString
as the value type, you can add a listener which sets the custom string as the value of the ComboBox withsetValue(Object)
.Setting to
true
also 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
-true
to enable custom value set events,false
to disable themSee 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 -
isRequired
public boolean isRequired()Sets whether the component requires a value to be considered in a valid state.
Returns:
true
if the component requires a value to be valid -
setRequired
public void setRequired(boolean required) Whether the component requires a value to be considered in a valid state.
Parameters:
required
-true
if the component requires a value to be valid -
getPlaceholder
The placeholder text that should be displayed in the input element, when the user has not entered a value
Returns:
the placeholder text
-
setPlaceholder
Sets the placeholder text that should be displayed in the input element, when the user has not entered a value
Parameters:
placeholder
- the placeholder text -
setItemLabelGenerator
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 itemReturns:
string label 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 using
setItemLabelGenerator(ItemLabelGenerator)
.Parameters:
renderer
- a renderer for the items in the selection list of the ComboBox, notnull
Note 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
Description copied from interface:
HasValue
Sets the value of this object. If the new value is not equal to
getValue()
, fires a value change event. May throwIllegalArgumentException
if the value is not acceptable.Implementation note: the implementing class should document whether null values are accepted or not, and override
HasValue.getEmptyValue()
if the empty value is notnull
.Specified by:
setValue
in interfaceHasValue<TComponent extends ComboBoxBase<TComponent,
TItem, TValue>, TItem> Overrides:
setValue
in classAbstractField<TComponent extends ComboBoxBase<TComponent,
TItem, TValue>, TValue> Parameters:
value
- the new value -
onAttach
Description copied from class:
Component
Called when the component is attached to a UI.
The default implementation does nothing.
This method is invoked before the
AttachEvent
is fired for the component. -
onDetach
Description copied from class:
Component
Called when the component is detached from a UI.
The default implementation does nothing.
This method is invoked before the
DetachEvent
is fired for the component. -
addCustomValueSetListener
public Registration addCustomValueSetListener(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
String
as 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 filledReturns:
a
Registration
for removing the event listenerSee 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:
getListDataView
in interfaceHasListDataView<TComponent extends ComboBoxBase<TComponent,
TItem, TValue>, TItem> Returns:
the list data view that provides access to the items in the ComboBox
-
setItems
Sets the items from the given Collection and returns a
ListDataView
that provides information and allows operations on the 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:
setItems
in interfaceHasListDataView<TComponent extends ComboBoxBase<TComponent,
TItem, TValue>, TItem> Parameters:
items
- the items to display, notnull
Returns:
ListDataView providing access to the items
-
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 thesetItems
methods 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 displayReturns:
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 thesetItems
methods 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 displayReturns:
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, 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 thesetItems
methods 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
Description copied from interface:
HasListDataView
Sets a ListDataProvider for the component to use and returns a
ListDataView
that provides information and allows operations on the items.Specified by:
setItems
in interfaceHasListDataView<TComponent extends ComboBoxBase<TComponent,
TItem, TValue>, TItem> Parameters:
dataProvider
- ListDataProvider providing items to the component.Returns:
ListDataView providing access to the items
-
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:
getLazyDataView
in interfaceHasLazyDataView<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(CallbackDataProvider.FetchCallback<TItem, C> fetchCallback, 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 fororderCountStr
are 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 callbackParameters:
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 filterReturns:
ComboBoxLazyDataView instance for further configuration
-
setItemsWithFilterConverter
public <C> ComboBoxLazyDataView<TItem> setItemsWithFilterConverter(CallbackDataProvider.FetchCallback<TItem, C> fetchCallback, CallbackDataProvider.CountCallback<TItem, C> countCallback, 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 fororderCountStr
are 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 callbacksParameters:
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 filterReturns:
ComboBoxLazyDataView instance for further configuration
-
setItems
public ComboBoxLazyDataView<TItem> setItems(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:
setItems
in interfaceHasLazyDataView<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 objectReturns:
ComboBoxLazyDataView instance for further configuration
-
setItems
public ComboBoxLazyDataView<TItem> setItems(CallbackDataProvider.FetchCallback<TItem, String> fetchCallback, 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:
setItems
in interfaceHasLazyDataView<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 queryReturns:
ComboBoxLazyDataView instance for further configuration
-
setItems
Description copied from interface:
HasLazyDataView
Supply items with a
BackEndDataProvider
that lazy loads items from a backend. Note that component will query the data provider for the item count. In case that is not desired for performance reasons, useHasLazyDataView.setItems(CallbackDataProvider.FetchCallback)
instead.The returned data view object can be used for further configuration, or later on fetched with
HasLazyDataView.getLazyDataView()
. For using in-memory data, likeCollection
, useHasListDataView.setItems(Collection)
instead.Specified by:
setItems
in interfaceHasLazyDataView<TComponent extends ComboBoxBase<TComponent,
TItem, TValue>, TItem, TValue> Parameters:
dataProvider
- BackEndDataProvider instanceReturns:
LazyDataView instance for further configuration
-
getGenericDataView
Gets the generic data view for the ComboBox. This data view can be used when
getListDataView()
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:
getGenericDataView
in interfaceHasDataView<TComponent extends ComboBoxBase<TComponent,
TItem, TValue>, TItem, TValue> Returns:
the generic
DataView
implementation for ComboBoxSee Also:
-
setItems
Description copied from interface:
HasDataView
Set a generic data provider for the component to use and returns the base
DataView
that provides API to get information on the items.This method should be used only when the data provider type is not either
ListDataProvider
orBackEndDataProvider
.Specified by:
setItems
in interfaceHasDataView<TComponent extends ComboBoxBase<TComponent,
TItem, TValue>, TItem, TValue> Parameters:
dataProvider
- DataProvider instance to use, notnull
Returns:
DataView providing information on the data
-
setItems
Deprecated.does not work so don't useThe method is not supported for the
ComboBox
component, use another overloaded method with filter convertersetItems(InMemoryDataProvider, SerializableFunction)
Always throws an
UnsupportedOperationException
.Specified by:
setItems
in interfaceHasDataView<TComponent extends ComboBoxBase<TComponent,
TItem, TValue>, TItem, TValue> Parameters:
dataProvider
- InMemoryDataProvider to use, notnull
Returns:
DataView providing information on the data
Throws:
UnsupportedOperationException
- when using this method with anInMemoryDataProvider
See Also:
-
setItems
public ComboBoxDataView<TItem> setItems(InMemoryDataProvider<TItem> inMemoryDataProvider, SerializableFunction<String, 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
ListDataProvider
instead of aInMemoryDataProvider
is recommended to get access toListDataView
API by usingsetItems(ListDataProvider)
.Parameters:
inMemoryDataProvider
- InMemoryDataProvider to use, notnull
filterConverter
- a function which converts a component's internal filter into a predicate applied to the data providerReturns:
DataView providing information on the data
-
getDataProvider
Gets the data provider used by this ComboBox.
Returns:
the data provider used by this ComboBox
-
isSelected
Whether the item is currently selected in the combo box.
Parameters:
item
- the item to checkReturns:
true
if the item is selected,false
otherwise -
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 component
Can be null if the constructor has not run yet
Returns:
the data controller
-
getDataCommunicator
Accesses the data communicator that is managed by the data controller
Can 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 controller
Can be null if the constructor has not run yet
Returns:
the data generator
-
getKeyMapper
Accesses the key mapper that is managed by the data controller
Can be null if the no data source has been set yet, or if the constructor has not run yet
Returns:
the key mapper
-
runBeforeClientResponse
Helper for running a command in the before client response hook
Parameters:
command
- the command to execute -
validate
protected void validate() -
addValidationStatusChangeListener
public Registration addValidationStatusChangeListener(ValidationStatusChangeListener<TValue> listener) Description copied from interface:
HasValidator
Enables the implementing components to notify changes in their validation status to the observers.
Note: This method can be overridden by the implementing classes e.g. components, to enable the associated
Binder.Binding
instance subscribing for their validation change events and revalidate itself.This method primarily designed for notifying the Binding about the validation status changes of a bound component at the client-side. WebComponents such as
<vaadin-date-picker>
or any other component that accept a formatted text as input should be able to communicate their invalid status to their server-side instance, and a bound server-side component instance must notify its binding about this validation status change as well. When the binding instance revalidates, a chain of validators and convertors get executed one of which is the default validator provided byHasValidator.getDefaultValidator()
. Thus, In order for the binding to be able to show/clear errors for its associated bound field, it is important that implementing components take that validation status into account while implementing any validator and converter includingHasValidator.getDefaultValidator()
. Here is an example:@Tag("date-picker-demo") public class DatePickerDemo implements HasValidator<LocalDate> { // Each web component has a way to communicate its validation status // to its server-side component instance. The following clientSideValid // state is introduced here just for the sake of simplicity of this code // snippet: boolean clientSideValid = true; /** * Note how
clientSideValid
engaged in the definition * of this method. It is important to reflect this status either * in the returning validation result of this method or any other * validation that is associated with this component. */ @Override public Validator getDefaultValidator() { return (value, valueContext) -> clientSideValid ? ValidationResult.ok() : ValidationResult.error("Invalid date format"); } private final Collection<ValidationStatusChangeListener<LocalDate>> validationStatusListeners = new ArrayList<>(); /** * This enables the binding to subscribe for the validation status * change events that are fired by this component and revalidate * itself respectively. */ @Override public Registration addValidationStatusChangeListener( ValidationStatusChangeListener<LocalDate> listener) { validationStatusListeners.add(listener); return () -> validationStatusListeners.remove(listener); } private void fireValidationStatusChangeEvent( boolean newValidationStatus) { if (this.clientSideValid != newValidationStatus) { this.clientSideValid = newValidationStatus; var event = new ValidationStatusChangeEvent<>(this, newValidationStatus); validationStatusListeners.forEach( listener -> listener.validationStatusChanged(event)); } } }Specified by:
addValidationStatusChangeListener
in interfaceHasValidator<TComponent extends ComboBoxBase<TComponent,
TItem, TValue>> Returns:
Registration of the added listener.
See Also:
-