public abstract class AbstractTextField extends AbstractField<String> implements HasValueChangeMode, FieldEvents.FocusNotifier, FieldEvents.BlurNotifier
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Sizeable.Unit
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
DESIGN_ATTR_PLAIN_TEXT
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
Modifier | Constructor and Description |
---|---|
protected |
AbstractTextField()
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addBlurListener(FieldEvents.BlurListener listener)
Adds a
FieldEvents.BlurListener to this component, which gets fired when this
component loses keyboard focus. |
Registration |
addFocusListener(FieldEvents.FocusListener listener)
Adds a
FieldEvents.FocusListener to this component, which gets fired when
this component receives keyboard focus. |
protected void |
doSetValue(String value)
Sets the value of this field.
|
int |
getCursorPosition()
Returns the last known cursor position of the field.
|
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. |
String |
getEmptyValue()
Returns the value that represents an empty value.
|
int |
getMaxLength()
Returns the maximum number of characters in the field.
|
String |
getPlaceholder()
Returns the current placeholder text.
|
protected AbstractTextFieldState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected AbstractTextFieldState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
String |
getValue()
Returns the current value of this object.
|
ValueChangeMode |
getValueChangeMode()
Returns the currently set
ValueChangeMode . |
int |
getValueChangeTimeout()
Returns the currently set timeout, in milliseconds, for how often
HasValue.ValueChangeEvent s are triggered if the current
ValueChangeMode is set to either ValueChangeMode.LAZY or
ValueChangeMode.TIMEOUT . |
void |
readDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Reads the component state from the given design.
|
void |
selectAll()
Selects all text in the field.
|
void |
setCursorPosition(int pos)
Sets the cursor position in the field.
|
void |
setMaxLength(int maxLength)
Sets the maximum number of characters in the field.
|
void |
setPlaceholder(String placeholder)
Sets the placeholder text.
|
void |
setSelection(int start,
int length)
Sets the range of text to be selected.
|
void |
setValue(String value)
Sets the value of this text field.
|
void |
setValueChangeMode(ValueChangeMode mode)
Sets the mode how the TextField triggers
HasValue.ValueChangeEvent s. |
void |
setValueChangeTimeout(int timeout)
Sets how often
HasValue.ValueChangeEvent s are triggered when the
ValueChangeMode is set to either ValueChangeMode.LAZY or
ValueChangeMode.TIMEOUT . |
void |
writeDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Writes the component state to the given design.
|
addValueChangeListener, createValueChange, focus, getTabIndex, isDifferentValue, isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible, setTabIndex, setValue
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
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
clear, getDefaultValidator, getOptionalValue, isEmpty
public void setValue(String value)
getValue()
, fires a ValueChangeEvent
. Throws
NullPointerException
if the value is null.setValue
in interface HasValue<String>
setValue
in class AbstractField<String>
value
- the new value, not null
NullPointerException
- if value
is null
public int getMaxLength()
public void setMaxLength(int maxLength)
maxLength
- the maxLength to setpublic String getPlaceholder()
setPlaceholder(String)
public void setPlaceholder(String placeholder)
placeholder
- the placeholder text to setpublic String getValue()
HasValue
Implementation note: the implementing class should document whether null values may be returned or not.
public void selectAll()
As a side effect the field will become focused.
public void setSelection(int start, int length)
As a side effect the field will become focused.
start
- the position of the first character to be selectedlength
- the number of characters to be selectedpublic void setCursorPosition(int pos)
pos
- the position for the cursorpublic int getCursorPosition()
public Registration addFocusListener(FieldEvents.FocusListener listener)
FieldEvents.FocusListener
to this component, which gets fired when
this component receives keyboard focus.addFocusListener
in interface FieldEvents.FocusNotifier
listener
- the focus listenerRegistration
public Registration addBlurListener(FieldEvents.BlurListener listener)
FieldEvents.BlurListener
to this component, which gets fired when this
component loses keyboard focus.addBlurListener
in interface FieldEvents.BlurNotifier
listener
- the blur listenerRegistration
public void setValueChangeMode(ValueChangeMode mode)
HasValueChangeMode
HasValue.ValueChangeEvent
s.setValueChangeMode
in interface HasValueChangeMode
mode
- the new modeValueChangeMode
public ValueChangeMode getValueChangeMode()
HasValueChangeMode
ValueChangeMode
.getValueChangeMode
in interface HasValueChangeMode
HasValue.ValueChangeEvent
s.ValueChangeMode
public void setValueChangeTimeout(int timeout)
HasValueChangeMode
HasValue.ValueChangeEvent
s are triggered when the
ValueChangeMode
is set to either ValueChangeMode.LAZY
or
ValueChangeMode.TIMEOUT
.setValueChangeTimeout
in interface HasValueChangeMode
timeout
- timeout in milliseconds, must be greater or equal to 0ValueChangeMode
public int getValueChangeTimeout()
HasValueChangeMode
HasValue.ValueChangeEvent
s are triggered if the current
ValueChangeMode
is set to either ValueChangeMode.LAZY
or
ValueChangeMode.TIMEOUT
.getValueChangeTimeout
in interface HasValueChangeMode
HasValue.ValueChangeEvent
s are triggered.public 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 AbstractField<String>
design
- The element to obtain the state fromdesignContext
- The DesignContext instance used for parsing the designprotected AbstractTextFieldState getState()
AbstractComponent
getState
in class AbstractField<String>
protected AbstractTextFieldState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractField<String>
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
protected void doSetValue(String value)
AbstractField
IllegalArgumentException
if the value is invalid. Typically saves
the value to shared state.doSetValue
in class AbstractField<String>
value
- the new value of the fieldpublic 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 AbstractField<String>
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 AbstractField<String>
public String getEmptyValue()
HasValue
By default HasValue
is expected to support null
as empty
values. Specific implementations might not support this.
getEmptyValue
in interface HasValue<String>
Binder#bind(HasValue, ValueProvider, Setter)
Copyright © 2018 Vaadin Ltd. All rights reserved.