Class ComboBox<T>
- Type Parameters:
T- the type of the items to be selectable from the combo box
- All Implemented Interfaces:
AttachNotifier,BlurNotifier<ComboBox<T>>,DetachNotifier,Focusable<ComboBox<T>>,FocusNotifier<ComboBox<T>>,HasAriaLabel,HasElement,HasEnabled,HasHelper,HasLabel,HasSize,HasStyle,HasTheme,HasValidation,HasValue<AbstractField.ComponentValueChangeEvent<ComboBox<T>,,T>, T> HasValueAndElement<AbstractField.ComponentValueChangeEvent<ComboBox<T>,,T>, T> HasAllowedCharPattern,HasAutoOpen,HasClearButton,HasClientValidation,HasOverlayClassName,HasPrefix,HasThemeVariant<ComboBoxVariant>,HasTooltip,HasValidationProperties,HasValidator<T>,HasDataView<T,,String, ComboBoxDataView<T>> HasLazyDataView<T,,String, ComboBoxLazyDataView<T>> HasListDataView<T,,ComboBoxListDataView<T>> Serializable
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 ComboBoxBase.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. ComboBoxBase.setItems(ItemFilter, Collection), filtering will happen in the
server. To enable client-side filtering with larger data sets, you can
override the pageSize to 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA callback method for fetching items.static interfacePredicate to checkComboBoxitems against user typed strings.Nested classes/interfaces inherited from class com.vaadin.flow.component.combobox.ComboBoxBase
ComboBoxBase.CustomValueSetEvent<TComponent extends ComboBoxBase<TComponent,?, ?>> 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.ClientValidatedEventNested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>> -
Constructor Summary
ConstructorsConstructorDescriptionComboBox()Default constructor.ComboBox(int pageSize) Creates an empty combo box with the defined page size for lazy loading.ComboBox(HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<ComboBox<T>, T>> listener) Constructs a combo box with a value change listener.Creates an empty combo box with the defined label.ComboBox(String label, HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<ComboBox<T>, T>> listener) Constructs a combo box with the defined label and a value change listener.ComboBox(String label, HasValue.ValueChangeListener<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.Creates a combo box with the defined label and populated with the items in the array. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value that represents an empty value.The pattern to validate the input withprotected booleanisSelected(T item) Whether the item is currently selected in the combo box.protected voidRefresh value / selection of the web component after changes that might affect the presentation / rendering of itemsvoidsetPattern(String pattern) Sets the pattern with which to validate the inputMethods inherited from class com.vaadin.flow.component.combobox.ComboBoxBase
addCustomValueSetListener, addValidationStatusChangeListener, generateLabel, getAriaLabel, getAriaLabelledBy, getDataCommunicator, getDataController, getDataGenerator, getDataProvider, getFilter, getGenericDataView, getItemLabelGenerator, getKeyMapper, getLazyDataView, getListDataView, getPageSize, getPlaceholder, getRenderManager, isAllowCustomValue, isAutofocus, isOpened, isRequired, onAttach, onDetach, runBeforeClientResponse, setAllowCustomValue, setAriaLabel, setAriaLabelledBy, setAutofocus, setFilter, setItemLabelGenerator, setItems, setItems, setItems, setItems, setItems, setItems, setItems, setItems, setItems, setItems, setItems, setItemsWithFilterConverter, setItemsWithFilterConverter, setOpened, setPageSize, setPlaceholder, setRenderer, setRequired, setValue, validateMethods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEventMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, 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.data.provider.HasListDataView
setItemsMethods inherited from interface com.vaadin.flow.component.shared.HasOverlayClassName
getOverlayClassName, setOverlayClassNameMethods inherited from interface com.vaadin.flow.component.shared.HasPrefix
getPrefixComponent, setPrefixComponentMethods 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.HasThemeVariant
addThemeVariants, removeThemeVariantsMethods 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
getDefaultValidatorMethods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
-
Constructor Details
-
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- See Also:
-
ComboBox
public ComboBox()Default constructor. Creates an empty combo box. -
ComboBox
Creates an empty combo box with the defined label.- Parameters:
label- the label describing the combo box- See Also:
-
ComboBox
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:
-
ComboBox
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:
-
ComboBox
public ComboBox(HasValue.ValueChangeListener<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:
-
ComboBox
public ComboBox(String label, HasValue.ValueChangeListener<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:
-
ComboBox
@SafeVarargs public ComboBox(String label, HasValue.ValueChangeListener<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:
-
-
Method Details
-
getPattern
The pattern to validate the input with- Returns:
- the pattern to validate the input with
-
setPattern
Sets the pattern with which to validate the input- Parameters:
pattern- the pattern to validate the input with
-
refreshValue
protected void refreshValue()Description copied from class:ComboBoxBaseRefresh value / selection of the web component after changes that might affect the presentation / rendering of items- Specified by:
refreshValuein classComboBoxBase<ComboBox<T>,T, T>
-
isSelected
Description copied from class:ComboBoxBaseWhether the item is currently selected in the combo box.- Specified by:
isSelectedin classComboBoxBase<ComboBox<T>,T, T> - Parameters:
item- the item to check- Returns:
trueif the item is selected,falseotherwise
-
getEmptyValue
Description copied from interface:HasValueReturns the value that represents an empty value.By default
HasValueis expected to supportnullas empty values. Specific implementations might not support this.- Specified by:
getEmptyValuein interfaceHasValue<AbstractField.ComponentValueChangeEvent<ComboBox<T>,T>, T> - Overrides:
getEmptyValuein classAbstractField<ComboBox<T>,T> - Returns:
- empty value
-