com.vaadin.ui
Class AbstractTextField

java.lang.Object
  extended by com.vaadin.terminal.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.AbstractField<String>
              extended by com.vaadin.ui.AbstractTextField
All Implemented Interfaces:
Buffered, BufferedValidatable, Property<String>, Property.Editor, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Validatable, Action.ShortcutNotifier, FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, FieldEvents.TextChangeNotifier, MethodEventSource, Connector, ClientConnector, RpcTarget, Sizeable, Vaadin6Component, VariableOwner, Component, Component.Focusable, Field<String>, Serializable, EventListener
Direct Known Subclasses:
PasswordField, TextArea, TextField

public abstract class AbstractTextField
extends AbstractField<String>
implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier, FieldEvents.TextChangeNotifier, Vaadin6Component

See Also:
Serialized Form

Nested Class Summary
 class AbstractTextField.TextChangeEventImpl
           
static class AbstractTextField.TextChangeEventMode
          Different modes how the TextField can trigger FieldEvents.TextChangeEvents.
 
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractField
AbstractField.FocusShortcut, AbstractField.ReadOnlyStatusChangeEvent
 
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler
 
Nested classes/interfaces inherited from interface com.vaadin.terminal.VariableOwner
VariableOwner.ErrorEvent
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.terminal.Sizeable
Sizeable.Unit
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Field
Field.ValueChangeEvent
 
Nested classes/interfaces inherited from interface com.vaadin.data.Buffered
Buffered.SourceException
 
Nested classes/interfaces inherited from interface com.vaadin.data.Property
Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.Transactional<T>, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer
 
Field Summary
 
Fields inherited from interface com.vaadin.terminal.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
protected AbstractTextField()
           
 
Method Summary
 void addListener(FieldEvents.BlurListener listener)
          Adds a BlurListener to the Component which gets fired when a Field loses keyboard focus.
 void addListener(FieldEvents.FocusListener listener)
          Adds a FocusListener to the Component which gets fired when a Field receives keyboard focus.
 void addListener(FieldEvents.TextChangeListener listener)
           
 void changeVariables(Object source, Map<String,Object> variables)
          Called when one or more variables handled by the implementing class are changed.
 int getColumns()
          Gets the number of columns in the editor.
 int getCursorPosition()
          Returns the last known cursor position of the field.
 String getInputPrompt()
          Gets the current input prompt.
 int getMaxLength()
          Returns the maximum number of characters in the field.
 String getNullRepresentation()
          Gets the null-string representation.
 AbstractTextFieldState getState()
          Returns the shared state bean with information to be sent from the server to the client.
 AbstractTextField.TextChangeEventMode getTextChangeEventMode()
           
 int getTextChangeTimeout()
          Gets the timeout used to fire FieldEvents.TextChangeEvents when the getTextChangeEventMode() is AbstractTextField.TextChangeEventMode.LAZY or AbstractTextField.TextChangeEventMode.TIMEOUT.
 Class<String> getType()
          Returns the type of the Field.
protected  boolean isEmpty()
          Is the field empty? In general, "empty" state is same as null.
 boolean isNullSettingAllowed()
          Is setting nulls with null-string representation allowed.
 void paintContent(PaintTarget target)
           Paints the Paintable into a UIDL stream.
 void removeListener(FieldEvents.BlurListener listener)
          Removes a BlurListener from the Component.
 void removeListener(FieldEvents.FocusListener listener)
          Removes a FocusListener from the Component.
 void removeListener(FieldEvents.TextChangeListener listener)
           
 void selectAll()
          Selects all text in the field.
 void setColumns(int columns)
          Sets the number of columns in the editor.
 void setCursorPosition(int pos)
          Sets the cursor position in the field.
 void setInputPrompt(String inputPrompt)
          Sets the input prompt - a textual prompt that is displayed when the field would otherwise be empty, to prompt the user for input.
protected  void setInternalValue(String newValue)
          Sets the internal field value.
 void setMaxLength(int maxLength)
          Sets the maximum number of characters in the field.
 void setNullRepresentation(String nullRepresentation)
          Sets the null-string representation.
 void setNullSettingAllowed(boolean nullSettingAllowed)
          Sets the null conversion mode.
 void setSelectionRange(int pos, int length)
          Sets the range of text to be selected.
 void setTextChangeEventMode(AbstractTextField.TextChangeEventMode inputEventMode)
          Sets the mode how the TextField triggers FieldEvents.TextChangeEvents.
 void setTextChangeTimeout(int timeout)
          The text change timeout modifies how often text change events are communicated to the application when getTextChangeEventMode() is AbstractTextField.TextChangeEventMode.LAZY or AbstractTextField.TextChangeEventMode.TIMEOUT.
 void setValue(Object newValue)
          Sets the value of the field.
 void updateState()
          Called before the shared state is sent to the client.
 
Methods inherited from class com.vaadin.ui.AbstractField
addListener, addListener, addValidator, attach, commit, detach, discard, fireReadOnlyStatusChange, fireValueChange, focus, getConversionError, getConversionError, getConvertedValue, getConverter, getCurrentBufferedSourceException, getErrorMessage, getInternalValue, getPropertyDataSource, getRequiredError, getTabIndex, getValidators, getValue, isBuffered, isInvalidAllowed, isInvalidCommitted, isModified, isReadOnly, isReadThrough, isRequired, isValid, isValidationVisible, isWriteThrough, readOnlyStatusChange, removeAllValidators, removeListener, removeListener, removeValidator, setBuffered, setConversionError, setConvertedValue, setConverter, setConverter, setCurrentBufferedSourceException, setInvalidAllowed, setInvalidCommitted, setPropertyDataSource, setReadOnly, setReadThrough, setRequired, setRequiredError, setTabIndex, setValidationVisible, setValue, setWriteThrough, shouldHideErrors, toString, validate, validate, valueChange
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addListener, addListener, addListener, addShortcutListener, addStyleName, findAncestor, fireComponentErrorEvent, fireComponentEvent, fireEvent, getActionManager, getApplication, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getHeight, getHeightUnits, getIcon, getListeners, getLocale, getParent, getRoot, getStyle, getStyleName, getWidth, getWidthUnits, handleError, hasListeners, isConnectorEnabled, isEnabled, isImmediate, isVisible, removeListener, removeListener, removeListener, removeListener, removeListener, removeShortcutListener, removeStyleName, requestRepaint, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setErrorHandler, setHeight, setHeight, setIcon, setImmediate, setLocale, setParent, setSizeFull, setSizeUndefined, setStyle, setStyleName, setVisible, setWidth, setWidth
 
Methods inherited from class com.vaadin.terminal.AbstractClientConnector
addExtension, addMethodInvocationToQueue, createState, getAllChildrenIterable, getConnectorId, getExtensions, getRpcManager, getRpcProxy, getStateType, registerRpc, registerRpc, removeExtension, requestRepaintAll, retrievePendingRpcCalls
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.vaadin.terminal.VariableOwner
isEnabled, isImmediate
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, attach, getApplication, getCaption, getDebugId, getIcon, getLocale, getParent, getRoot, getStyleName, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setDebugId, setEnabled, setIcon, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.vaadin.terminal.gwt.server.ClientConnector
detach, getExtensions, getStateType, isConnectorEnabled, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setParent
 
Methods inherited from interface com.vaadin.terminal.gwt.client.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.terminal.gwt.server.RpcTarget
getRpcManager
 
Methods inherited from interface com.vaadin.terminal.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setSizeFull, setSizeUndefined, setWidth, setWidth
 
Methods inherited from interface com.vaadin.event.Action.ShortcutNotifier
addShortcutListener, removeShortcutListener
 

Constructor Detail

AbstractTextField

protected AbstractTextField()
Method Detail

getState

public AbstractTextFieldState 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().

Specified by:
getState in interface Connector
Specified by:
getState in interface Component
Overrides:
getState in class AbstractField<String>
Returns:
updated component shared state

updateState

public void updateState()
Description copied from interface: Component
Called before the shared state is sent to the client. Gives the component an opportunity to set computed/dynamic state values e.g. state values that depend on other component features.

This method must not alter the component hierarchy in any way.

Specified by:
updateState in interface Component
Overrides:
updateState in class AbstractField<String>

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException
Description copied from interface: Vaadin6Component

Paints the Paintable into a UIDL stream. This method creates the UIDL sequence describing it and outputs it to the given UIDL stream.

It is called when the contents of the component should be painted in response to the component first being shown or having been altered so that its visual representation is changed.

Specified by:
paintContent in interface Vaadin6Component
Parameters:
target - the target UIDL stream where the component should paint itself to.
Throws:
PaintException - if the paint operation failed.

changeVariables

public void changeVariables(Object source,
                            Map<String,Object> variables)
Description copied from interface: VariableOwner
Called when one or more variables handled by the implementing class are changed.

Specified by:
changeVariables in interface VariableOwner
Parameters:
source - the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.
variables - the Mapping from variable names to new variable values.

getType

public Class<String> getType()
Description copied from class: AbstractField
Returns the type of the Field. The methods getValue and setValue must be compatible with this type: one must be able to safely cast the value returned from getValue to the given type and pass any variable assignable to this type as an argument to setValue.

Specified by:
getType in interface Property<String>
Specified by:
getType in class AbstractField<String>
Returns:
the type of the Field

getNullRepresentation

public String getNullRepresentation()
Gets the null-string representation.

The null-valued strings are represented on the user interface by replacing the null value with this string. If the null representation is set null (not 'null' string), painting null value throws exception.

The default value is string 'null'.

Returns:
the String Textual representation for null strings.
See Also:
isNullSettingAllowed()

isNullSettingAllowed

public boolean isNullSettingAllowed()
Is setting nulls with null-string representation allowed.

If this property is true, writing null-representation string to text field always sets the field value to real null. If this property is false, null setting is not made, but the null values are maintained. Maintenance of null-values is made by only converting the textfield contents to real null, if the text field matches the null-string representation and the current value of the field is null.

By default this setting is false

Returns:
boolean Should the null-string represenation be always converted to null-values.
See Also:
getNullRepresentation()

setNullRepresentation

public void setNullRepresentation(String nullRepresentation)
Sets the null-string representation.

The null-valued strings are represented on the user interface by replacing the null value with this string. If the null representation is set null (not 'null' string), painting null value throws exception.

The default value is string 'null'

Parameters:
nullRepresentation - Textual representation for null strings.
See Also:
setNullSettingAllowed(boolean)

setNullSettingAllowed

public void setNullSettingAllowed(boolean nullSettingAllowed)
Sets the null conversion mode.

If this property is true, writing null-representation string to text field always sets the field value to real null. If this property is false, null setting is not made, but the null values are maintained. Maintenance of null-values is made by only converting the textfield contents to real null, if the text field matches the null-string representation and the current value of the field is null.

By default this setting is false.

Parameters:
nullSettingAllowed - Should the null-string representation always be converted to null-values.
See Also:
getNullRepresentation()

isEmpty

protected boolean isEmpty()
Description copied from class: AbstractField
Is the field empty? In general, "empty" state is same as null. As an exception, TextField also treats empty string as "empty".

Overrides:
isEmpty in class AbstractField<String>

getMaxLength

public int getMaxLength()
Returns the maximum number of characters in the field. Value -1 is considered unlimited. Terminal may however have some technical limits.

Returns:
the maxLength

setMaxLength

public void setMaxLength(int maxLength)
Sets the maximum number of characters in the field. Value -1 is considered unlimited. Terminal may however have some technical limits.

Parameters:
maxLength - the maxLength to set

getColumns

public int getColumns()
Gets the number of columns in the editor. If the number of columns is set 0, the actual number of displayed columns is determined implicitly by the adapter.

Returns:
the number of columns in the editor.

setColumns

public void setColumns(int columns)
Sets the number of columns in the editor. If the number of columns is set 0, the actual number of displayed columns is determined implicitly by the adapter.

Parameters:
columns - the number of columns to set.

getInputPrompt

public String getInputPrompt()
Gets the current input prompt.

Returns:
the current input prompt, or null if not enabled
See Also:
setInputPrompt(String)

setInputPrompt

public void setInputPrompt(String inputPrompt)
Sets the input prompt - a textual prompt that is displayed when the field would otherwise be empty, to prompt the user for input.

Parameters:
inputPrompt -

setInternalValue

protected void setInternalValue(String newValue)
Description copied from class: AbstractField
Sets the internal field value. This is purely used by AbstractField to change the internal Field value. It does not trigger valuechange events. It can be overridden by the inheriting classes to update all dependent variables. Subclasses can also override AbstractField.getInternalValue() if necessary.

Overrides:
setInternalValue in class AbstractField<String>
Parameters:
newValue - the new value to be set.

setValue

public void setValue(Object newValue)
              throws Property.ReadOnlyException
Description copied from class: AbstractField
Sets the value of the field.

Specified by:
setValue in interface Property<String>
Overrides:
setValue in class AbstractField<String>
Parameters:
newValue - the New value of the field.
Throws:
Property.ReadOnlyException - if the object is in read-only mode

setTextChangeEventMode

public void setTextChangeEventMode(AbstractTextField.TextChangeEventMode inputEventMode)
Sets the mode how the TextField triggers FieldEvents.TextChangeEvents.

Parameters:
inputEventMode - the new mode
See Also:
AbstractTextField.TextChangeEventMode

getTextChangeEventMode

public AbstractTextField.TextChangeEventMode getTextChangeEventMode()
Returns:
the mode used to trigger FieldEvents.TextChangeEvents.

addListener

public void addListener(FieldEvents.TextChangeListener listener)
Specified by:
addListener in interface FieldEvents.TextChangeNotifier

removeListener

public void removeListener(FieldEvents.TextChangeListener listener)
Specified by:
removeListener in interface FieldEvents.TextChangeNotifier

setTextChangeTimeout

public void setTextChangeTimeout(int timeout)
The text change timeout modifies how often text change events are communicated to the application when getTextChangeEventMode() is AbstractTextField.TextChangeEventMode.LAZY or AbstractTextField.TextChangeEventMode.TIMEOUT.

Parameters:
timeout - the timeout in milliseconds
See Also:
getTextChangeEventMode()

getTextChangeTimeout

public int getTextChangeTimeout()
Gets the timeout used to fire FieldEvents.TextChangeEvents when the getTextChangeEventMode() is AbstractTextField.TextChangeEventMode.LAZY or AbstractTextField.TextChangeEventMode.TIMEOUT.

Returns:
the timeout value in milliseconds

selectAll

public void selectAll()
Selects all text in the field.

Since:
6.4

setSelectionRange

public void setSelectionRange(int pos,
                              int length)
Sets the range of text to be selected. As a side effect the field will become focused.

Parameters:
pos - the position of the first character to be selected
length - the number of characters to be selected
Since:
6.4

setCursorPosition

public void setCursorPosition(int pos)
Sets the cursor position in the field. As a side effect the field will become focused.

Parameters:
pos - the position for the cursor
Since:
6.4

getCursorPosition

public int getCursorPosition()
Returns the last known cursor position of the field.

Note that due to the client server nature or the GWT terminal, Vaadin cannot provide the exact value of the cursor position in most situations. The value is updated only when the client side terminal communicates to TextField, like on ValueChangeEvents and FieldEvents.TextChangeEvent s. This may change later if a deep push integration is built to Vaadin.

Returns:
the cursor position

addListener

public void addListener(FieldEvents.FocusListener listener)
Description copied from interface: FieldEvents.FocusNotifier
Adds a FocusListener to the Component which gets fired when a Field receives keyboard focus.

Specified by:
addListener in interface FieldEvents.FocusNotifier
See Also:
FieldEvents.FocusListener

removeListener

public void removeListener(FieldEvents.FocusListener listener)
Description copied from interface: FieldEvents.FocusNotifier
Removes a FocusListener from the Component.

Specified by:
removeListener in interface FieldEvents.FocusNotifier
See Also:
FieldEvents.FocusListener

addListener

public void addListener(FieldEvents.BlurListener listener)
Description copied from interface: FieldEvents.BlurNotifier
Adds a BlurListener to the Component which gets fired when a Field loses keyboard focus.

Specified by:
addListener in interface FieldEvents.BlurNotifier
See Also:
FieldEvents.BlurListener

removeListener

public void removeListener(FieldEvents.BlurListener listener)
Description copied from interface: FieldEvents.BlurNotifier
Removes a BlurListener from the Component.

Specified by:
removeListener in interface FieldEvents.BlurNotifier
See Also:
FieldEvents.BlurListener


Copyright © 2000-2011 Vaadin Ltd. All Rights Reserved.