com.vaadin.ui.
Class NativeSelect<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.ui.AbstractComponent
-
- com.vaadin.ui.AbstractListing<T>
-
- com.vaadin.ui.AbstractSingleSelect<T>
-
- com.vaadin.ui.NativeSelect<T>
-
Type Parameters:
T
- the data item typeAll Implemented Interfaces:
HasDataProvider<T>
,HasItems<T>
,HasValue<T>
,ContextClickEvent.ContextClickNotifier
,FieldEvents.BlurNotifier
,FieldEvents.FocusNotifier
,MethodEventSource
,ClientConnector
,Sizeable
,Connector
,Component
,Component.Focusable
,SingleSelect<T>
,Serializable
public class NativeSelect<T> extends AbstractSingleSelect<T> implements FieldEvents.FocusNotifier, FieldEvents.BlurNotifier, HasDataProvider<T>
A simple drop-down select component. Represented on the client side by a "native" HTML
<select>
element. Lacks advanced features such as lazy loading, filtering, and adding new items.Author:
Vaadin Ltd.
See Also:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractListing
AbstractListing.AbstractListingExtension<T>
-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
-
Nested classes/interfaces inherited from interface com.vaadin.data.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
-
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
-
-
Field Summary
-
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
-
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
-
-
Constructor Summary
Constructors Constructor Description NativeSelect()
Creates a new
NativeSelect
with an empty caption and no items.NativeSelect(String caption)
Creates a new
NativeSelect
with the given caption and no items.NativeSelect(String caption, DataProvider<T,?> dataProvider)
Creates a new
NativeSelect
with the given caption, using the givenDataProvider
as the source of data items.NativeSelect(String caption, Collection<T> items)
Creates a new
NativeSelect
with the given caption, containing the data items in the given collection.
-
Method Summary
All Methods Modifier and Type Method Description Registration
addBlurListener(FieldEvents.BlurListener listener)
Adds a
BlurListener
to the Component which gets fired when aField
loses keyboard focus.Registration
addFocusListener(FieldEvents.FocusListener listener)
Adds a
FocusListener
to the Component which gets fired when aField
receives keyboard focus.DataProvider<T,?>
getDataProvider()
Returns the source of data items used by this listing.
String
getEmptySelectionCaption()
Returns the empty selection caption.
ItemCaptionGenerator<T>
getItemCaptionGenerator()
Gets the item caption generator that is used to produce the strings shown in the combo box for each item.
protected NativeSelectState
getState()
Returns the shared state bean with information to be sent from the server to the client.
protected NativeSelectState
getState(boolean markAsDirty)
Returns the shared state for this connector.
int
getVisibleItemCount()
Gets the number of items that are visible.
boolean
isEmptySelectionAllowed()
Returns whether the user is allowed to select nothing in the combo box.
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 in the combo box.
void
setEmptySelectionCaption(String caption)
Sets the empty selection caption.
void
setItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator)
Sets the item caption generator that is used to produce the strings shown in the combo box for each item.
void
setVisibleItemCount(int visibleItemCount)
Sets the number of items that are visible.
-
Methods inherited from class com.vaadin.ui.AbstractSingleSelect
addSelectionListener, addValueChangeListener, getCustomAttributes, getSelectedItem, getValue, isReadOnly, isRequiredIndicatorVisible, isSelected, keyToItem, readItem, readItems, setReadOnly, setRequiredIndicatorVisible, setSelectedItem, setSelectedItem, setValue, updateSelectedItemState, writeItem
-
Methods inherited from class com.vaadin.ui.AbstractListing
addDataGenerator, deserializeDeclarativeRepresentation, doReadDesign, doWriteDesign, focus, getDataCommunicator, getItemIconGenerator, getTabIndex, internalGetDataProvider, internalSetDataProvider, internalSetDataProvider, readDesign, readItem, removeDataGenerator, serializeDeclarativeRepresentation, setItemIconGenerator, setTabIndex, writeDesign, writeItems
-
Methods inherited from class com.vaadin.ui.AbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeight, setHeightFull, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthFull, setWidthUndefined
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, readDesign, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible, writeDesign
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface com.vaadin.data.HasDataProvider
setItems
-
Methods inherited from interface com.vaadin.data.HasValue
clear, getDefaultValidator, getEmptyValue, getOptionalValue, isEmpty
-
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefined
-
-
-
-
Constructor Detail
-
NativeSelect
public NativeSelect()
Creates a new
NativeSelect
with an empty caption and no items.
-
NativeSelect
public NativeSelect(String caption)
Creates a new
NativeSelect
with the given caption and no items.Parameters:
caption
- the component caption to set, null for no caption
-
NativeSelect
public NativeSelect(String caption, Collection<T> items)
Creates a new
NativeSelect
with the given caption, containing the data items in the given collection.Parameters:
caption
- the component caption to set, null for no captionitems
- the data items to use, not null
-
NativeSelect
public NativeSelect(String caption, DataProvider<T,?> dataProvider)
Creates a new
NativeSelect
with the given caption, using the givenDataProvider
as the source of data items.Parameters:
caption
- the component caption to set, null for no captiondataProvider
- the source of data items to use, not null
-
-
Method Detail
-
addFocusListener
public Registration addFocusListener(FieldEvents.FocusListener listener)
Description copied from interface:
FieldEvents.FocusNotifier
Adds a
FocusListener
to the Component which gets fired when aField
receives keyboard focus.Specified by:
addFocusListener
in interfaceFieldEvents.FocusNotifier
Parameters:
listener
- the focus listener to add, not nullReturns:
a registration object for removing the listener
See Also:
-
addBlurListener
public Registration addBlurListener(FieldEvents.BlurListener listener)
Description copied from interface:
FieldEvents.BlurNotifier
Adds a
BlurListener
to the Component which gets fired when aField
loses keyboard focus.Specified by:
addBlurListener
in interfaceFieldEvents.BlurNotifier
Parameters:
listener
- the blur listener to add, not nullReturns:
a registration object for removing the listener
See Also:
-
getState
protected NativeSelectState getState()
Description copied from class:
AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().
Overrides:
getState
in classAbstractSingleSelect<T>
Returns:
updated component shared state
-
getState
protected NativeSelectState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classAbstractSingleSelect<T>
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
getDataProvider
public DataProvider<T,?> getDataProvider()
Description copied from interface:
HasItems
Returns the source of data items used by this listing.
Specified by:
getDataProvider
in interfaceHasItems<T>
Returns:
the data provider, not null
-
setDataProvider
public void setDataProvider(DataProvider<T,?> dataProvider)
Description copied from interface:
HasDataProvider
Sets the data provider for this listing. The data provider is queried for displayed items as needed.
Specified by:
setDataProvider
in interfaceHasDataProvider<T>
Parameters:
dataProvider
- the data provider, not null
-
setItemCaptionGenerator
public void setItemCaptionGenerator(ItemCaptionGenerator<T> itemCaptionGenerator)
Description copied from class:
AbstractListing
Sets the item caption generator that is used to produce the strings shown in the combo box for each item. By default,
String.valueOf(Object)
is used.Overrides:
setItemCaptionGenerator
in classAbstractListing<T>
Parameters:
itemCaptionGenerator
- the item caption provider to use, not null
-
getItemCaptionGenerator
public ItemCaptionGenerator<T> getItemCaptionGenerator()
Description copied from class:
AbstractListing
Gets the item caption generator that is used to produce the strings shown in the combo box for each item.
Overrides:
getItemCaptionGenerator
in classAbstractListing<T>
Returns:
the item caption generator used, not null
-
isEmptySelectionAllowed
public boolean isEmptySelectionAllowed()
Returns whether the user is allowed to select nothing in the combo box.
Returns:
true if empty selection is allowed, false otherwise
Since:
8.0
-
setEmptySelectionAllowed
public void setEmptySelectionAllowed(boolean emptySelectionAllowed)
Sets whether the user is allowed to select nothing in the combo box. When true, a special empty item is shown to the user.
Parameters:
emptySelectionAllowed
- true to allow not selecting anything, false to require selectionSince:
8.0
-
getEmptySelectionCaption
public String getEmptySelectionCaption()
Returns the empty selection caption.
The empty string
""
is the default empty selection caption.Returns:
the empty selection caption, not
null
Since:
8.0
See Also:
setEmptySelectionAllowed(boolean)
,isEmptySelectionAllowed()
,setEmptySelectionCaption(String)
,AbstractSingleSelect.isSelected(Object)
-
setEmptySelectionCaption
public void setEmptySelectionCaption(String caption)
Sets the empty selection caption.
The empty string
""
is the default empty selection caption.If empty selection is allowed via the
setEmptySelectionAllowed(boolean)
method (it is by default) then the empty item will be shown with the given caption.Parameters:
caption
- the caption to set, notnull
Since:
8.0
See Also:
-
setVisibleItemCount
public void setVisibleItemCount(int visibleItemCount)
Sets the number of items that are visible. If only one item is visible, then the box will be displayed as a drop-down list (the default).
Parameters:
visibleItemCount
- the visible item countThrows:
IllegalArgumentException
- if the value is smaller than oneSince:
8.1
-
getVisibleItemCount
public int getVisibleItemCount()
Gets the number of items that are visible. If only one item is visible, then the box will be displayed as a drop-down list.
Returns:
the visible item count
Since:
8.1
-
-