Class AbstractLookupField<T,SelectT,ComboboxT extends com.vaadin.flow.component.HasEnabled & com.vaadin.flow.component.HasValidation & com.vaadin.flow.component.HasSize & com.vaadin.flow.component.HasValue<?,SelectT>,ComponentT extends AbstractLookupField<T,SelectT,ComboboxT,ComponentT,FilterType>,FilterType>
- Type Parameters:
T- the type of the items shown in the combo box and gridSelectT- the value type of the field (a single item or a set of items)ComboboxT- the type of the combo box used as the fieldComponentT- the concrete component type, used for the fluent value-change APIFilterType- the type of the filter used to query the data provider
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.ClickNotifier<com.vaadin.flow.component.html.Div>,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasComponents,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasOrderedComponents,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasText,com.vaadin.flow.component.HasTheme,com.vaadin.flow.component.HasValidation,com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComponentT,,SelectT>, SelectT> com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComponentT,,SelectT>, SelectT> com.vaadin.flow.data.binder.HasFilterableDataProvider<T,,FilterType> com.vaadin.flow.data.binder.HasItems<T>,Serializable
- Direct Known Subclasses:
CustomFilterLookupField,CustomFilterMultiSelectLookupField
vcf-lookup-field webcomponent.
A lookup field is a combination of a combo box and a dialog for advanced search.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEvent fired when the user clicks the create item button.static classEvent fired when the user filters the grid through the custom filter.static classThe internationalization properties forLookupField.Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText
com.vaadin.flow.component.HasText.WhiteSpaceNested 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<?>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ComboboxTCombo box used as the field.static final StringDefault message shown when the selection is empty.protected static final StringName of the slot holding the field (combo box).protected final com.vaadin.flow.function.SerializableFunction<String, FilterType> Converts the combo box filter string into the data provider filter type.protected final com.vaadin.flow.function.SerializableFunction<FilterType, String> Converts the data provider filter type back into a combo box filter string.protected static final StringAttribute key used to assign a component to a slot. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractLookupField(com.vaadin.flow.function.SerializableFunction<String, FilterType> filterConverter, com.vaadin.flow.function.SerializableFunction<FilterType, String> invertedFilterConverter) Creates a lookup field with the given filter converters. -
Method Summary
Modifier and TypeMethodDescriptioncom.vaadin.flow.shared.RegistrationaddCreateItemListener(com.vaadin.flow.component.ComponentEventListener<AbstractLookupField.CreateItemEvent> listener) Add an action when the user click on create itemvoidaddEmptySelectionListener(Runnable notificationWhenEmptySelection) Replace the default notification to an actioncom.vaadin.flow.shared.RegistrationaddFilterListener(com.vaadin.flow.component.ComponentEventListener<AbstractLookupField.FilterEvent<FilterType>> listener) Add an action when the user filtersvoidaddThemeVariants(LookupFieldVariant... variants) Adds the theme variants of this component.protected abstract voidCopy the selected value of the grid into the fieldprotected abstract voidCopy the selected value of the field into the gridvoidClose the dialogvoidSelect and close the dialogabstract ComboboxTGets the internal combo box used as the field.com.vaadin.flow.component.grid.Grid<T> getGrid()Gets the internal grid shown in the advanced search dialog.getI18n()Gets the internationalization object previously set for this component.booleanGets whether the select button is disabled or send an error when the selection is empty or not.booleanGets whether dialog is enabled to be dragged or not.booleanbooleanisModal()Gets whether component is set as modal or modeless dialog.booleanGets whether dialog is enabled to be resized or not.voidopen()Opens the combo box overlay.abstract voidsetComboBox(ComboboxT comboBox) Set the comboBoxvoidsetCreateVisible(boolean createVisible) Sets whether the create button is visible.abstract voidsetDataProvider(com.vaadin.flow.component.combobox.ComboBox.ItemFilter<T> itemFilter, com.vaadin.flow.data.provider.ListDataProvider<T> listDataProvider) Sets a list data provider with an item filter as the data provider.<C> voidsetDataProvider(com.vaadin.flow.data.provider.DataProvider<T, C> dataProvider, com.vaadin.flow.function.SerializableFunction<FilterType, C> filterConverter) abstract voidsetDataProvider(com.vaadin.flow.data.provider.ListDataProvider<T> listDataProvider) Sets a list data provider as the data provider.voidsetDraggable(boolean draggable) Sets whether dialog is enabled to be dragged by the user or not.voidsetEnabled(boolean enabled) voidsetErrorMessage(String errorMessage) voidsetFilter(LookupFieldFilter<FilterType> filter) Set the filter with a custom componentvoidsetFooterComponent(com.vaadin.flow.component.Component footer) Set the footer with a custom component WARNING: You have to implement your own buttons to select and close the dialogvoidSet the gridvoidsetGridWidth(String width) Set the width of the grid Also set a max width to 100%voidSet the header of the dialogvoidsetHeaderComponent(com.vaadin.flow.component.Component header) Set the header with a custom componentvoidSets the internationalization properties for this component.voidsetInvalid(boolean invalid) abstract voidsetItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator) Sets the item label generator that is used to produce the strings shown in the combo box for each item.voidsetItems(com.vaadin.flow.component.combobox.ComboBox.ItemFilter<T> itemFilter, Collection<T> items) Sets the items to display, using the given item filter for the combo box.voidsetItems(Collection<T> items) Filtering will use a case insensitive match to show all items where the filter text is a substring of the label displayed for that item, which you can configure withsetItemLabelGenerator(ItemLabelGenerator).abstract voidSet the label of the fieldvoidsetModal(boolean modal) Sets whether component will open modal or modeless dialog.voidsetReadOnly(boolean readOnly) voidsetRequiredIndicatorVisible(boolean requiredIndicatorVisible) voidsetResizable(boolean resizable) Sets whether dialog can be resized by user or not.voidsetSelectionDisabledIfEmpty(boolean defaultselectdisabled) Sets whether the select button is disabled or send an error when the selection is empty or not.voidsetThemeVariants(LookupFieldVariant variants) Sets the theme variants of this component.Methods inherited from class com.vaadin.flow.component.HtmlComponent
getTitle, setTitleMethods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, 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.ClickNotifier
addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasComponents
add, add, add, addComponentAsFirst, addComponentAtIndex, bindChildren, getChildren, getComponentAt, getComponentCount, indexOf, remove, remove, removeAll, replaceMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabledMethods inherited from interface com.vaadin.flow.data.binder.HasFilterableDataProvider
setDataProviderMethods inherited from interface com.vaadin.flow.data.binder.HasItems
setItems, setItemsMethods 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.HasText
bindText, getText, getWhiteSpace, setText, setWhiteSpaceMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.HasValidation
setManualValidationMethods inherited from interface com.vaadin.flow.component.HasValue
addValueChangeListener, bindValue, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValueMethods inherited from interface com.vaadin.flow.component.HasValueAndElement
bindReadOnly, bindRequiredIndicatorVisible, isReadOnly, isRequiredIndicatorVisible
-
Field Details
-
FIELD_SLOT_NAME
Name of the slot holding the field (combo box).- See Also:
-
SLOT_KEY
Attribute key used to assign a component to a slot.- See Also:
-
DEFAULT_EMPTY_SELECTION
Default message shown when the selection is empty.- See Also:
-
comboBox
protected ComboboxT extends com.vaadin.flow.component.HasEnabled & com.vaadin.flow.component.HasValidation & com.vaadin.flow.component.HasSize & com.vaadin.flow.component.HasValue<?,SelectT> comboBoxCombo box used as the field. -
filterConverter
Converts the combo box filter string into the data provider filter type. -
invertedFilterConverter
protected final com.vaadin.flow.function.SerializableFunction<FilterType,String> invertedFilterConverterConverts the data provider filter type back into a combo box filter string.
-
-
Constructor Details
-
AbstractLookupField
public AbstractLookupField(com.vaadin.flow.function.SerializableFunction<String, FilterType> filterConverter, com.vaadin.flow.function.SerializableFunction<FilterType, String> invertedFilterConverter) Creates a lookup field with the given filter converters.- Parameters:
filterConverter- converts the combo box filter string into the data provider filter typeinvertedFilterConverter- converts the data provider filter type back into a combo box filter string
-
-
Method Details
-
setGrid
Set the grid- Parameters:
grid- the grid
-
setComboBox
Set the comboBox- Parameters:
comboBox- the comboBox
-
getComboBox
Gets the internal combo box used as the field.- Returns:
- the internal field
-
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).- Specified by:
setItemsin interfacecom.vaadin.flow.data.binder.HasItems<T>- Parameters:
items- the data items to display
-
setItems
public void setItems(com.vaadin.flow.component.combobox.ComboBox.ItemFilter<T> itemFilter, Collection<T> items) Sets the items to display, using the given item filter for the combo box.- Parameters:
itemFilter- filter to check if an item is shown when user typed some text into the ComboBoxitems- the data items to display
-
setDataProvider
public abstract void setDataProvider(com.vaadin.flow.data.provider.ListDataProvider<T> listDataProvider) Sets a list data provider as the data provider.- Parameters:
listDataProvider- the list data provider to use, notnull
-
setDataProvider
public abstract void setDataProvider(com.vaadin.flow.component.combobox.ComboBox.ItemFilter<T> itemFilter, com.vaadin.flow.data.provider.ListDataProvider<T> listDataProvider) Sets a list data provider with an item filter as the data provider.- Parameters:
itemFilter- filter to check if an item is shown when user typed some text into the ComboBoxlistDataProvider- the list data provider to use, notnull
-
setDataProvider
public <C> void setDataProvider(com.vaadin.flow.data.provider.DataProvider<T, C> dataProvider, com.vaadin.flow.function.SerializableFunction<FilterType, C> filterConverter) -
getGrid
Gets the internal grid shown in the advanced search dialog.- Returns:
- the internal grid
-
copyFieldValueFromGrid
protected abstract void copyFieldValueFromGrid()Copy the selected value of the grid into the field -
copyFieldValueToGrid
protected abstract void copyFieldValueToGrid()Copy the selected value of the field into the grid -
setItemLabelGenerator
public abstract void setItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator) Sets the item label generator that is used to produce the strings shown in the combo box for each item. By default,String.valueOf(Object)is used.- Parameters:
itemLabelGenerator- the item label provider to use, not null
-
setGridWidth
Set the width of the grid Also set a max width to 100%- Parameters:
width- the width to set, may benull
-
setThemeVariants
Sets the theme variants of this component. This method overwrites any previous set theme variants.- Parameters:
variants- theme variant
-
addThemeVariants
Adds the theme variants of this component.- Parameters:
variants- theme variant
-
setHeader
Set the header of the dialog- Parameters:
header- text for the header of the dialog
-
setLabel
Set the label of the field- Parameters:
label- label of the field
-
setModal
public void setModal(boolean modal) Sets whether component will open modal or modeless dialog.Note: When dialog is set to be modeless, then it's up to you to provide means for it to be closed (eg. a button that calls
Dialog.close()). The reason being that a modeless dialog allows user to interact with the interface under it and won't be closed by clicking outside or the ESC key.- Parameters:
modal-falseto enable dialog to open as modeless modal,trueotherwise.
-
isModal
public boolean isModal()Gets whether component is set as modal or modeless dialog.- Returns:
trueif modal dialog (default),falseotherwise.
-
setDraggable
public void setDraggable(boolean draggable) Sets whether dialog is enabled to be dragged by the user or not.To allow an element inside the dialog to be dragged by the user (for instance, a header inside the dialog), a class
"draggable"can be added to it (seeHasStyle.addClassName(String)).Note: If draggable is enabled and dialog is opened without first being explicitly attached to a parent, then it won't restore its last position in the case the user closes and opens it again. Reason being that a self attached dialog is removed from the DOM when it's closed and position is not synched.
- Parameters:
draggable-trueto enable dragging of the dialog,falseotherwise
-
isDraggable
public boolean isDraggable()Gets whether dialog is enabled to be dragged or not.- Returns:
trueif dragging is enabled,falseotherwise (default).
-
setResizable
public void setResizable(boolean resizable) Sets whether dialog can be resized by user or not.- Parameters:
resizable-trueto enabled resizing of the dialog,falseotherwise.
-
isResizable
public boolean isResizable()Gets whether dialog is enabled to be resized or not.- Returns:
trueif resizing is enabled,falseotherwiser (default).
-
setSelectionDisabledIfEmpty
public void setSelectionDisabledIfEmpty(boolean defaultselectdisabled) Sets whether the select button is disabled or send an error when the selection is empty or not.- Parameters:
defaultselectdisabled-trueto disabled the button if no item is disabled,falseotherwise.
-
getSelectionDisabledIfEmpty
public boolean getSelectionDisabledIfEmpty()Gets whether the select button is disabled or send an error when the selection is empty or not.- Returns:
trueif resizing is enabled,falseotherwiser (default).
-
getI18n
Gets the internationalization object previously set for this component.Note: updating the object content that is gotten from this method will not update the lang on the component if not set back using
setI18n(LookupFieldI18n)- Returns:
- the i18n object. It will be
null, If the i18n properties weren't set.
-
setI18n
Sets the internationalization properties for this component.- Parameters:
i18n- the internationalized properties, notnull
-
isInvalid
public boolean isInvalid()- Specified by:
isInvalidin interfacecom.vaadin.flow.component.HasValidation
-
setInvalid
public void setInvalid(boolean invalid) - Specified by:
setInvalidin interfacecom.vaadin.flow.component.HasValidation
-
setReadOnly
public void setReadOnly(boolean readOnly) -
setEnabled
public void setEnabled(boolean enabled) - Specified by:
setEnabledin interfacecom.vaadin.flow.component.HasEnabled
-
setErrorMessage
- Specified by:
setErrorMessagein interfacecom.vaadin.flow.component.HasValidation
-
getErrorMessage
- Specified by:
getErrorMessagein interfacecom.vaadin.flow.component.HasValidation
-
setRequiredIndicatorVisible
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible) -
setHeaderComponent
public void setHeaderComponent(com.vaadin.flow.component.Component header) Set the header with a custom component- Parameters:
header- custom header
-
setFilter
Set the filter with a custom component- Parameters:
filter- custom filter
-
addEmptySelectionListener
Replace the default notification to an action- Parameters:
notificationWhenEmptySelection- action to run when the selection is empty and the select button is clicked
-
addFilterListener
public com.vaadin.flow.shared.Registration addFilterListener(com.vaadin.flow.component.ComponentEventListener<AbstractLookupField.FilterEvent<FilterType>> listener) Add an action when the user filters- Parameters:
listener- the listener to add, notnull- Returns:
- a handle that can be used for removing the listener
-
addCreateItemListener
public com.vaadin.flow.shared.Registration addCreateItemListener(com.vaadin.flow.component.ComponentEventListener<AbstractLookupField.CreateItemEvent> listener) Add an action when the user click on create item- Parameters:
listener- the listener to add, notnull- Returns:
- a handle that can be used for removing the listener
-
setCreateVisible
public void setCreateVisible(boolean createVisible) Sets whether the create button is visible.- Parameters:
createVisible-trueto show the create button,falseto hide it
-
open
public void open()Opens the combo box overlay.
-