T
- the type of the items for the select@JsModule(value="./selectConnector.js") public class Select<T> extends GeneratedVaadinSelect<Select<T>,T> implements HasDataProvider<T>, HasItemsAndComponents<T>, HasSize, HasValidation, SingleSelect<Select<T>,T>
This is a server side Java integration for <vaadin-select>
web
component.
For usage examples, see the demo in vaadin.com.
GeneratedVaadinSelect.InvalidChangeEvent<R extends GeneratedVaadinSelect<R,?>>, GeneratedVaadinSelect.OpenedChangeEvent<R extends GeneratedVaadinSelect<R,?>>
AbstractField.ComponentValueChangeEvent<C extends Component,V>
HasItemsAndComponents.ItemComponent<T>
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
BlurNotifier.BlurEvent<C extends Component>
FocusNotifier.FocusEvent<C extends Component>
Modifier and Type | Field and Description |
---|---|
static String |
LABEL_ATTRIBUTE |
Constructor and Description |
---|
Select()
Constructs a select.
|
Select(T... items)
Constructs a select with the given items.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Component... components)
Adds the given components as children of this component.
|
void |
addComponentAsFirst(Component component)
Adds the given component as the first child of this component.
|
void |
addComponentAtIndex(int index,
Component component)
Adds the given component as child of this component at the specific
index.
|
void |
addComponents(T afterItem,
Component... components)
Adds the components after the given item.
|
void |
addToPrefix(Component... components)
Adds the given components as children of this component at the slot
'prefix'.
|
Stream<Component> |
getChildren()
Gets the child components of this component.
|
DataProvider<T,?> |
getDataProvider()
Gets the data provider.
|
String |
getEmptySelectionCaption() |
String |
getErrorMessage()
Gets the error message to show to the user on invalid selection
|
SerializablePredicate<T> |
getItemEnabledProvider()
Returns the item enabled predicate.
|
ItemLabelGenerator<T> |
getItemLabelGenerator()
Gets the item label generator.
|
ComponentRenderer<? extends Component,T> |
getItemRenderer()
Returns the item component renderer.
|
String |
getLabel()
Gets the string for the label element.
|
String |
getPlaceholder()
Gets the placeholder hint set for the user.
|
protected boolean |
hasValidValue()
Checks whether the element property has a value that can be converted to
the model type.
|
boolean |
isAutofocus()
Gets whether this select has been set to autofocus when the page loads.
|
boolean |
isEmptySelectionAllowed()
Returns whether the user is allowed to select nothing.
|
boolean |
isInvalid()
Gets whether the select is currently in invalid state.
|
boolean |
isRequiredIndicatorVisible()
Checks whether the required indicator is visible.
|
protected void |
onAttach(AttachEvent attachEvent)
Called when the component is attached to a UI.
|
void |
onEnabledStateChanged(boolean enabled)
Handle component enable state when the enabled state changes.
|
void |
prependComponents(T beforeItem,
Component... components)
Adds the components before the given item.
|
void |
remove(Component... components)
Removes the given child components from this component.
|
void |
removeAll()
Removes all child components that are not items.
|
void |
setAutofocus(boolean autofocus)
Sets the select to have focus when the page loads.
|
void |
setDataProvider(DataProvider<T,?> dataProvider)
Sets the data provider for this listing.
|
void |
setEmptySelectionAllowed(boolean emptySelectionAllowed)
Sets whether the user is allowed to select nothing.
|
void |
setEmptySelectionCaption(String emptySelectionCaption)
Sets the empty selection caption when
setEmptySelectionAllowed(boolean) has been enabled. |
void |
setErrorMessage(String errorMessage)
Sets the error message to show to the user on invalid selection.
|
void |
setInvalid(boolean invalid)
Sets the select to show as invalid state and display error message.
|
void |
setItemEnabledProvider(SerializablePredicate<T> itemEnabledProvider)
Sets the item enabled predicate for this select.
|
void |
setItemLabelGenerator(ItemLabelGenerator<T> itemLabelGenerator)
Sets the item label generator.
|
void |
setLabel(String label)
Sets the string for the label element.
|
void |
setPlaceholder(String placeholder)
Sets the placeholder hint for the user.
|
void |
setRenderer(ComponentRenderer<? extends Component,T> renderer)
Sets the item renderer for this select group.
|
void |
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets the required indicator visible or not.
|
void |
setTextRenderer(ItemLabelGenerator<T> itemLabelGenerator)
Convenience setter for creating a
TextRenderer from the given
function that converts the item to a string. |
addInvalidChangeListener, addOpenedChangeListener, getErrorMessageString, getLabelString, getNameString, getPlaceholderString, isAutofocusBoolean, isDisabledBoolean, isInvalidBoolean, isOpenedBoolean, isReadonlyBoolean, isRequiredBoolean, render, setDisabled, setName, setOpened, setReadonly, setRequired, validate
getSynchronizationRegistration, setPresentationValue, setSynchronizedEvent
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEquals
addListener, fireEvent, from, get, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, isVisible, onDetach, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setItems
getItemPosition
add
getHeight, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, setHeight, setHeightFull, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidthFull
isReadOnly, setReadOnly
addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValue
isEnabled, setEnabled
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
addBlurListener
addFocusListener
addAttachListener
addDetachListener
public static final String LABEL_ATTRIBUTE
public Select()
public Select(T... items)
items
- the items for the selectpublic ComponentRenderer<? extends Component,T> getItemRenderer()
null
if none setsetRenderer(ComponentRenderer)
public void setRenderer(ComponentRenderer<? extends Component,T> renderer)
Default is null
which means that the item's Object.toString()
method is used and set as the text content of the vaadin item element.
renderer
- the item renderer, or null
to clearpublic void setTextRenderer(ItemLabelGenerator<T> itemLabelGenerator)
TextRenderer
from the given
function that converts the item to a string.
NOTE: even though this accepts an ItemLabelGenerator
,
this is not the same as
setItemLabelGenerator(ItemLabelGenerator)
which does a different
thing.
itemLabelGenerator
- the function that creates the text content from the item, not
null
public void setEmptySelectionAllowed(boolean emptySelectionAllowed)
true
a special empty item is shown to the user.
Default is false
. The empty selection item can be customized with
setEmptySelectionCaption(String)
.
emptySelectionAllowed
- true
to allow not selecting anything, false
to
require selectionsetEmptySelectionCaption(String)
public boolean isEmptySelectionAllowed()
true
if empty selection is allowed, false
otherwisepublic void setEmptySelectionCaption(String emptySelectionCaption)
setEmptySelectionAllowed(boolean)
has been enabled. The caption
is shown for the empty selection item in the drop down.
When the empty selection item is selected, the select shows the value
provided by setItemLabelGenerator(ItemLabelGenerator)
for the
null
item, or the string set with setPlaceholder(String)
or an empty string if not placeholder is set.
Default is an empty string "", which will show the place holder when selected.
emptySelectionCaption
- the empty selection caption to set, not null
setEmptySelectionAllowed(boolean)
public String getEmptySelectionCaption()
public SerializablePredicate<T> getItemEnabledProvider()
null
if not setsetItemEnabledProvider(com.vaadin.flow.function.SerializablePredicate<T>)
public void setItemEnabledProvider(SerializablePredicate<T> itemEnabledProvider)
true
) or disabled (false
). Disabled items are displayed
as grayed out and the user cannot select them.
By default is null
and all the items are enabled.
itemEnabledProvider
- the item enable predicate or null
to clearpublic ItemLabelGenerator<T> getItemLabelGenerator()
Default is null
.
null
if not setpublic void setItemLabelGenerator(ItemLabelGenerator<T> itemLabelGenerator)
Default is null
and the text content generated for the item with
setRenderer(ComponentRenderer)
is used instead.
itemLabelGenerator
- the item label generator to set, or null
to clearpublic String getPlaceholder()
null
if none setpublic void setPlaceholder(String placeholder)
The placeholder will be displayed in the case that there is no item selected, or the selected item has an empty string label, or the selected item has no label and it's DOM content is empty.
Default value is null
.
setPlaceholder
in class GeneratedVaadinSelect<Select<T>,T>
placeholder
- the placeholder to set, or null
to removepublic void setLabel(String label)
NOTE: the label must be set for the required indicator to be visible.
setLabel
in class GeneratedVaadinSelect<Select<T>,T>
label
- string or null
to clear itpublic String getLabel()
null
if not setpublic void setAutofocus(boolean autofocus)
Default is false
.
setAutofocus
in class GeneratedVaadinSelect<Select<T>,T>
autofocus
- the autofocus to setpublic boolean isAutofocus()
true
if set to autofocus, false
if notpublic void setDataProvider(DataProvider<T,?> dataProvider)
HasDataProvider
setDataProvider
in interface HasDataProvider<T>
dataProvider
- the data provider, not nullpublic DataProvider<T,?> getDataProvider()
null
public void onEnabledStateChanged(boolean enabled)
Component
By default this sets or removes the 'disabled' attribute from the element. This can be overridden to have custom handling.
onEnabledStateChanged
in class Component
enabled
- the new enabled state of the componentpublic void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
If set visible, it is visually indicated in the user interface.
The method is intended to be used with Binder
which does
server-side validation. In case HTML element has its own (client-side)
validation it should be disabled when
setRequiredIndicatorVisible(true)
is called and re-enabled
back on setRequiredIndicatorVisible(false)
. It's
responsibility of each component implementation to follow the contract so
that the method call doesn't do anything else than show/hide the
"required" indication. Usually components provide their own
setRequired
method which should be called in case the
client-side validation is required.
NOTE: The required indicator will not be visible, if the
setLabel(String)
property is not set for the select.
setRequiredIndicatorVisible
in interface HasValue<AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>
setRequiredIndicatorVisible
in interface HasValueAndElement<AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>
requiredIndicatorVisible
- true
to make the required indicator visible,
false
if notpublic boolean isRequiredIndicatorVisible()
setLabel(String)
property is not set for the select.isRequiredIndicatorVisible
in interface HasValue<AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>
isRequiredIndicatorVisible
in interface HasValueAndElement<AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>
true
if visible, false
if notpublic void setErrorMessage(String errorMessage)
setErrorMessage
in interface HasValidation
setErrorMessage
in class GeneratedVaadinSelect<Select<T>,T>
errorMessage
- the error message or null
to clear itpublic String getErrorMessage()
getErrorMessage
in interface HasValidation
null
if not setpublic void setInvalid(boolean invalid)
setInvalid
in interface HasValidation
setInvalid
in class GeneratedVaadinSelect<Select<T>,T>
invalid
- true
for invalid, false
for validpublic boolean isInvalid()
isInvalid
in interface HasValidation
true
for invalid, false
for validpublic void add(Component... components)
In case the any of the specified components has already been added to another parent, it will be removed from there and added to this one.
NOTE: If you add a component with the slot
attribute
set, it will be placed in the light-dom of the vaadin-select
instead of the drop down, similar to addToPrefix(Component...)
add
in interface HasComponents
components
- the components to addpublic void addComponents(T afterItem, Component... components)
HasItemsAndComponents
addComponents
in interface HasItemsAndComponents<T>
afterItem
- item to add components aftercomponents
- components to add after itempublic void prependComponents(T beforeItem, Component... components)
HasItemsAndComponents
prependComponents
in interface HasItemsAndComponents<T>
beforeItem
- item to add components in front ofcomponents
- components to add before itempublic void addComponentAtIndex(int index, Component component)
In case the specified component has already been added to another parent, it will be removed from there and added to this one.
NOTE: If you add a component with the slot
attribute
set, it will be placed in the light-dom of the vaadin-select
instead of the drop down, similar to addToPrefix(Component...)
addComponentAtIndex
in interface HasComponents
index
- the index, where the component will be added. The index must
be non-negative and may not exceed the children countcomponent
- the component to add, value should not be nullpublic void addComponentAsFirst(Component component)
In case the specified component has already been added to another parent, it will be removed from there and added to this one.
NOTE: If you add a component with the slot
attribute
set, it will be placed in the light-dom of the vaadin-select
instead of the drop down, similar to addToPrefix(Component...)
addComponentAsFirst
in interface HasComponents
component
- the component to add, value should not be nullpublic void addToPrefix(Component... components)
GeneratedVaadinSelect
addToPrefix
in class GeneratedVaadinSelect<Select<T>,T>
components
- The components to add.public Stream<Component> getChildren()
Component
The default implementation finds child components by traversing each
child Element
tree.
If the component is injected to a PolymerTemplate using the
@Id
annotation the getChildren method will only return
children added from the server side and will not return any children
declared in the template file.
getChildren
in class Component
Id
public void remove(Component... components)
NOTE: any component with the slot
attribute will be
attempted to removed from the light dom of the vaadin-select, instead of
inside the options drop down.
remove
in interface HasComponents
remove
in class GeneratedVaadinSelect<Select<T>,T>
components
- the components to removeIllegalArgumentException
- if any of the components is not a child of this componentpublic void removeAll()
HasItems.setItems(Object[])
.
NOTE: this will remove all non-items from the drop down and any slotted components from vaadin-select's light dom.
removeAll
in interface HasComponents
removeAll
in class GeneratedVaadinSelect<Select<T>,T>
HasComponents.removeAll()
protected boolean hasValidValue()
AbstractSinglePropertyField
false
. The default implementation always
return true
.hasValidValue
in class AbstractSinglePropertyField<Select<T>,T>
true
if the element property value can be converted
to the model type; otherwise false
protected void onAttach(AttachEvent attachEvent)
Component
The default implementation does nothing.
This method is invoked before the AttachEvent
is fired for the
component.
Copyright © 2020. All rights reserved.