Class SearchSelect<T>
- Type Parameters:
T- the item type
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.BlurNotifier<SearchSelect<T>>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.Focusable<SearchSelect<T>>,com.vaadin.flow.component.FocusNotifier<SearchSelect<T>>,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.HasValidation,com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<SearchSelect<T>,,T>, T> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<SearchSelect<T>,,T>, T> com.vaadin.flow.component.shared.HasClearButton,com.vaadin.flow.component.shared.HasTooltip,com.vaadin.flow.component.shared.HasValidationProperties,Serializable
Select (no
custom values), but you can type to filter.
Small and medium lists (up to 1000
items by default) are sent to the browser once and filtered there: typing
causes no server round trips at all; only the selected item is sent back. The
default filter matches all typed words in any order, ignoring case and accents
(see SearchMatching); provide your own with
setClientFilter(String). Items can be found by more than their label
with setSearchTextGenerator(ItemLabelGenerator).
Large lists — more in-memory items than the limit, or a backend query
given with setItems(CallbackDataProvider.FetchCallback) — are filtered
on the server, but only when the user pauses typing
(300 ms by default), so a fluent typist
causes one request rather than one per keystroke. Meanwhile, as long as the
typed text refines the previous search, the previous results are narrowed down
in the browser at once. At most 100 matches
are shown; typing more narrows them down.
Renders as Vaadin's vaadin-combo-box web component (look, keyboard use,
accessibility and theming as in the rest of a Vaadin app), driven by a small
connector of its own instead of Flow's ComboBox — no custom frontend
bundle needed.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField
com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V> 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.Focusable
com.vaadin.flow.component.Focusable.FocusJsNested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier
com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue
com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>> -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.SearchSelect(String label) Deprecated.SearchSelect(String label, Collection<T> items) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.The items shown for the given text: with in-memory items, those matching the default rule (the same the browser applies); with a backend query, its results.Deprecated.Deprecated.intDeprecated.com.vaadin.flow.component.ItemLabelGenerator<T> Deprecated.getItems()Deprecated.The in-memory items; empty when the items are queried from a backend (setItems(CallbackDataProvider.FetchCallback)).getSearchText(T item) Deprecated.The search text of an item (seesetSearchTextGenerator(com.vaadin.flow.component.ItemLabelGenerator<T>)).Deprecated.intDeprecated.booleanDeprecated.Whether filtering happens on the server (large list or backend query).booleanDeprecated.Whether a value is required; seesetRequired(boolean).protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) Deprecated.voidsetAriaLabel(String ariaLabel) Deprecated.The accessible name, for a field without a visible label (e.g. in a compact toolbar).voidsetAriaLabelledBy(String labelledBy) Deprecated.voidsetClientFilter(String functionBody) Deprecated.A custom filter, as the body of a JavaScript function(item, filter, normalize) => boolean:item.labelanditem.searchare the item's label and search text,filteris the typed text andnormalize(text)lower-cases and removes accents.voidsetClientSideItemLimit(int clientSideItemLimit) Deprecated.Up to how many in-memory items are filtered in the browser (default 1000); longer lists are filtered on the server.voidsetItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator) Deprecated.How an item is shown (default:toString()).voidDeprecated.Queries the items from a backend, e.g. a database, always filtered on the server.voidsetItems(Collection<T> items) Deprecated.The items to choose from, in the order shown.final voidDeprecated.protected voidsetPresentationValue(T value) Deprecated.voidsetRequired(boolean required) Deprecated.Whether a value is required: shows the required indicator, asHasValueAndElement.setRequiredIndicatorVisible(boolean)(which this is an alias for, as inComboBox).voidsetSearchTextGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> searchTextGenerator) Deprecated.The text searched for an item, when it should be found by more than its label, e.g. synonyms or codes (default: the label).voidsetServerFilterDelay(Duration serverFilterDelay) Deprecated.How long the user must pause typing before the filter is sent to the server (default 300 ms), when filtering on the server.voidsetServerResultLimit(int serverResultLimit) Deprecated.How many matches at most are shown when filtering on the server (default 100).Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField
getSynchronizationRegistration, hasValidValue, setSynchronizedEventMethods inherited from class com.vaadin.flow.component.AbstractField
addValueChangeListener, bindValue, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEqualsMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, getUIOrThrow, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisible, whenAttachedMethods 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, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasAriaLabel
setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.shared.HasClearButton
bindClearButtonVisible, isClearButtonVisible, setClearButtonVisibleMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabled, setEnabledMethods inherited from interface com.vaadin.flow.component.HasHelper
bindHelperText, getHelperComponent, getHelperText, setHelperComponent, setHelperTextMethods inherited from interface com.vaadin.flow.component.HasLabel
getLabel, setLabelMethods inherited from interface com.vaadin.flow.component.HasPlaceholder
bindPlaceholder, getPlaceholder, setPlaceholderMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, 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, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipMarkdown, setTooltipTextMethods inherited from interface com.vaadin.flow.component.HasValidation
setManualValidationMethods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties
getErrorMessage, isInvalid, setErrorMessage, setInvalidMethods inherited from interface com.vaadin.flow.component.HasValue
clear, getOptionalValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
bindReadOnly, bindRequiredIndicatorVisible, isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible
-
Constructor Details
-
SearchSelect
public SearchSelect()Deprecated. -
SearchSelect
Deprecated. -
SearchSelect
Deprecated.
-
-
Method Details
-
setRequired
public void setRequired(boolean required) Deprecated.Whether a value is required: shows the required indicator, asHasValueAndElement.setRequiredIndicatorVisible(boolean)(which this is an alias for, as inComboBox). Checking it is up to the server, e.g. Binder'sasRequired(). -
isRequired
public boolean isRequired()Deprecated.Whether a value is required; seesetRequired(boolean). -
setAriaLabel
Deprecated.The accessible name, for a field without a visible label (e.g. in a compact toolbar). Set as the web component'saccessibleName, as Vaadin's own fields do, so screen readers announce it on the input.- Specified by:
setAriaLabelin interfacecom.vaadin.flow.component.HasAriaLabel
-
getAriaLabel
Deprecated.- Specified by:
getAriaLabelin interfacecom.vaadin.flow.component.HasAriaLabel
-
setAriaLabelledBy
Deprecated.- Specified by:
setAriaLabelledByin interfacecom.vaadin.flow.component.HasAriaLabel
-
getAriaLabelledBy
Deprecated.- Specified by:
getAriaLabelledByin interfacecom.vaadin.flow.component.HasAriaLabel
-
setItems
Deprecated.The items to choose from, in the order shown. Up to theclient side item limitthey are filtered in the browser, above it on the server with the default rule (SearchMatching.matchesAllWords(java.lang.String, java.lang.String)on the search text). -
setItems
Deprecated. -
setItems
public void setItems(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T, String> fetch) Deprecated.Queries the items from a backend, e.g. a database, always filtered on the server. The query's filter is the typed text (empty for "no filter"); its limit is theresult limit. Example:select.setItems(query -> repository.findByNameContaining(query.getFilter().orElse(""), PageRequest.of(0, query.getLimit())).stream())SearchMatching.matchesAllWords(java.lang.String, java.lang.String)implements the default rule of the in-memory lists, if you want to match it. -
getItems
Deprecated.The in-memory items; empty when the items are queried from a backend (setItems(CallbackDataProvider.FetchCallback)). -
isFilteredOnServer
public boolean isFilteredOnServer()Deprecated.Whether filtering happens on the server (large list or backend query). -
setItemLabelGenerator
public void setItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator) Deprecated.How an item is shown (default:toString()). -
getItemLabelGenerator
Deprecated. -
setSearchTextGenerator
public void setSearchTextGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> searchTextGenerator) Deprecated.The text searched for an item, when it should be found by more than its label, e.g. synonyms or codes (default: the label). Not used with a backend query, which does its own matching. -
getSearchText
Deprecated.The search text of an item (seesetSearchTextGenerator(com.vaadin.flow.component.ItemLabelGenerator<T>)). -
setClientFilter
Deprecated.A custom filter, as the body of a JavaScript function(item, filter, normalize) => boolean:item.labelanditem.searchare the item's label and search text,filteris the typed text andnormalize(text)lower-cases and removes accents. Example (prefix match):return normalize(item.label).startsWith(normalize(filter));When filtering on the server, this only narrows down the previous results while waiting for the server; make the server side match the same way.
nullrestores the default: all words in any order, ignoring case and accents (SearchMatching.matchesAllWords(java.lang.String, java.lang.String)). -
setClientSideItemLimit
public void setClientSideItemLimit(int clientSideItemLimit) Deprecated.Up to how many in-memory items are filtered in the browser (default 1000); longer lists are filtered on the server. -
getClientSideItemLimit
public int getClientSideItemLimit()Deprecated. -
setServerFilterDelay
Deprecated.How long the user must pause typing before the filter is sent to the server (default 300 ms), when filtering on the server. -
getServerFilterDelay
Deprecated. -
setServerResultLimit
public void setServerResultLimit(int serverResultLimit) Deprecated.How many matches at most are shown when filtering on the server (default 100). -
getServerResultLimit
public int getServerResultLimit()Deprecated. -
filter
Deprecated.The items shown for the given text: with in-memory items, those matching the default rule (the same the browser applies); with a backend query, its results. Handy in tests and server-side logic. Limited to theresult limitwhen filtering on the server. -
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) Deprecated.- Overrides:
onAttachin classcom.vaadin.flow.component.Component
-
setPresentationValue
Deprecated.- Overrides:
setPresentationValuein classcom.vaadin.flow.component.AbstractSinglePropertyField<SearchSelect<T>,T>
-