T
- the input value typepublic abstract class AbstractField<T> extends AbstractComponent implements HasValue<T>, Component.Focusable
Component
allowing user
input. Implements HasValue
to represent the input value. Examples of
typical field components include text fields, date pickers, and check boxes.
This class replaces the Vaadin 7 com.vaadin.ui.AbstractField
class.
The old AbstractField
is retained, under the new name
AbstractField
, for compatibility and migration
purposes.
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Sizeable.Unit
DESIGN_ATTR_PLAIN_TEXT
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
Constructor and Description |
---|
AbstractField() |
Modifier and Type | Method and Description |
---|---|
Registration |
addValueChangeListener(HasValue.ValueChangeListener<T> listener)
Adds a value change listener.
|
protected HasValue.ValueChangeEvent<T> |
createValueChange(T oldValue,
boolean userOriginated)
Returns a new value change event instance.
|
protected abstract void |
doSetValue(T value)
Sets the value of this field.
|
void |
focus()
Sets the focus for this component if the component is
Focusable . |
protected Collection<String> |
getCustomAttributes()
Returns a collection of attributes that should not be handled by the
basic implementation of the
AbstractComponent.readDesign(Element, DesignContext)
and AbstractComponent.writeDesign(Element, DesignContext) methods. |
protected AbstractFieldState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected AbstractFieldState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
int |
getTabIndex()
Gets the tabulator index of the
Focusable component. |
protected boolean |
isDifferentValue(T newValue)
Called when a new value is set to determine whether the provided new
value is considered to be a change compared to the current value.
|
boolean |
isReadOnly()
Returns the read-only status from the state of this
AbstractComponent . |
boolean |
isRequiredIndicatorVisible()
Checks whether the required indicator is visible or not.
|
void |
readDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Reads the component state from the given design.
|
void |
setReadOnly(boolean readOnly)
Sets the read-only status in the state of this
AbstractComponent . |
void |
setRequiredIndicatorVisible(boolean visible)
Sets the visibility of the required indicator.
|
void |
setTabIndex(int tabIndex)
Sets the tabulator index of the
Focusable component. |
void |
setValue(T value)
Sets the value of this object.
|
protected boolean |
setValue(T value,
boolean userOriginated)
Sets the value of this field if it has changed and fires a value change
event.
|
void |
writeDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Writes the component state to the given design.
|
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, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthUndefined
addAttachListener, addDetachListener, addExtension, 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, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
clear, getDefaultValidator, getEmptyValue, getOptionalValue, getValue, isEmpty
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
public void setValue(T value)
HasValue
getValue()
, fires a value change event. May throw
IllegalArgumentException
if the value is not acceptable.
Implementation note: the implementing class should document whether null values are accepted or not.
public boolean isReadOnly()
AbstractComponent
AbstractComponent
. This method should be made public in
Components
that implement HasValue
.isReadOnly
in interface HasValue<T>
isReadOnly
in class AbstractComponent
true
if state has read-only on; false
if notAbstractComponent.setReadOnly(boolean)
public void setReadOnly(boolean readOnly)
AbstractComponent
.
This method should be made public in Components
that
implement HasValue
.
The server ignores (potentially forged) value change requests from the
client to fields that are read-only. Programmatically changing the field
value via #setValue(T)
is still possible.
The read-only mode is distinct from the disabled state. When disabled, a component cannot be interacted with at all, and its content should be considered irrelevant or not applicable. In contrast, the user should still be able to read the content and otherwise interact with a read-only field even though changing the value is disallowed.
setReadOnly
in interface HasValue<T>
setReadOnly
in class AbstractComponent
readOnly
- true
to set read-only mode, false
otherwise.public Registration addValueChangeListener(HasValue.ValueChangeListener<T> listener)
HasValue
HasValue
is changed either by the user or programmatically.addValueChangeListener
in interface HasValue<T>
listener
- the value change listener, not nullpublic void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Component
The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.
It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.
This method must not modify the design.
readDesign
in interface Component
readDesign
in class AbstractComponent
design
- The element to obtain the state fromdesignContext
- The DesignContext instance used for parsing the designpublic void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Component
The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.
This method must not modify the component state.
writeDesign
in interface Component
writeDesign
in class AbstractComponent
design
- The element to write the component state to. Any previous
attributes or child nodes are not cleared.designContext
- The DesignContext instance used for writing the designprotected Collection<String> getCustomAttributes()
AbstractComponent
AbstractComponent.readDesign(Element, DesignContext)
and AbstractComponent.writeDesign(Element, DesignContext)
methods. Typically these
are handled in a custom way in the overridden versions of the above
methodsgetCustomAttributes
in class AbstractComponent
protected boolean setValue(T value, boolean userOriginated)
doSetValue
to actually store the value.value
- the new value to setuserOriginated
- true
if this event originates from the client,
false
otherwise.true
if the value was updated, false
otherwiseprotected boolean isDifferentValue(T newValue)
doSetValue(Object)
should be called
and a value change event fired.newValue
- the new value candidate to check, may be null
true
if the provided value is considered to be
different and a value change event should be fired;
false
if the values are considered to be the same
and no value change should be firedprotected abstract void doSetValue(T value)
IllegalArgumentException
if the value is invalid. Typically saves
the value to shared state.value
- the new value of the fieldIllegalArgumentException
- if the value is invalidprotected HasValue.ValueChangeEvent<T> createValueChange(T oldValue, boolean userOriginated)
oldValue
- the value of this field before this value change eventuserOriginated
- true
if this event originates from the client,
false
otherwise.protected AbstractFieldState getState()
AbstractComponent
getState
in class AbstractComponent
protected AbstractFieldState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractComponent
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public void focus()
AbstractComponent
Focusable
.focus
in interface Component.Focusable
focus
in class AbstractComponent
FieldEvents
,
FieldEvents.FocusEvent
,
FieldEvents.FocusListener
,
FieldEvents.BlurEvent
,
FieldEvents.BlurListener
public int getTabIndex()
Component.Focusable
Focusable
component.getTabIndex
in interface Component.Focusable
Focusable
componentComponent.Focusable.setTabIndex(int)
public void setTabIndex(int tabIndex)
Component.Focusable
Focusable
component.
The tab index property is used to specify the order in which the
fields are focused when the user presses the Tab key. Components with
a defined tab index are focused sequentially first, and then the
components with no tab index.
Form loginBox = new Form(); loginBox.setCaption("Login"); layout.addComponent(loginBox); // Create the first field which will be focused TextField username = new TextField("User name"); loginBox.addField("username", username); // Set focus to the user name username.focus(); TextField password = new TextField("Password"); loginBox.addField("password", password); Button login = new Button("Login"); loginBox.getFooter().addComponent(login); // An additional component which natural focus order would // be after the button. CheckBox remember = new CheckBox("Remember me"); loginBox.getFooter().addComponent(remember); username.setTabIndex(1); password.setTabIndex(2); remember.setTabIndex(3); // Different than natural place login.setTabIndex(4);
After all focusable user interface components are done, the browser can begin again from the component with the smallest tab index, or it can take the focus out of the page, for example, to the location bar.
If the tab index is not set (is set to zero), the default tab order is used. The order is somewhat browser-dependent, but generally follows the HTML structure of the page.
A negative value means that the component is completely removed from the tabulation order and can not be reached by pressing the Tab key at all.
setTabIndex
in interface Component.Focusable
tabIndex
- the tab order of this component. Indexes usually start
from 1. Zero means that default tab order should be used.
A negative value means that the field should not be
included in the tabbing sequence.Component.Focusable.getTabIndex()
public void setRequiredIndicatorVisible(boolean visible)
AbstractComponent
If the component supports the required indicator (state extends
AbstractFieldState
), then expose this method and
AbstractComponent.isRequiredIndicatorVisible()
as public
in the component
and call this method.
This method will throw a IllegalStateException
if the component
state (returned by AbstractComponent.getState()
) does not inherit
AbstractFieldState
.
setRequiredIndicatorVisible
in interface HasValue<T>
setRequiredIndicatorVisible
in class AbstractComponent
visible
- true
to make the required indicator visible,
false
if notpublic boolean isRequiredIndicatorVisible()
AbstractComponent
This method will throw a IllegalStateException
if the component
state (returned by AbstractComponent.getState()
) does not inherit
AbstractFieldState
.
isRequiredIndicatorVisible
in interface HasValue<T>
isRequiredIndicatorVisible
in class AbstractComponent
true
if visible, false
if notAbstractComponent.setRequiredIndicatorVisible(boolean)
Copyright © 2018 Vaadin Ltd. All rights reserved.