com.itmill.toolkit.ui
Class TextField

java.lang.Object
  extended by com.itmill.toolkit.ui.AbstractComponent
      extended by com.itmill.toolkit.ui.AbstractField
          extended by com.itmill.toolkit.ui.TextField
All Implemented Interfaces:
Buffered, BufferedValidatable, Property, Property.Editor, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Validatable, MethodEventSource, Paintable, Sizeable, VariableOwner, Component, Component.Focusable, Field, EventListener
Direct Known Subclasses:
RichTextArea

public class TextField
extends AbstractField

A text editor component that can be bound to any bindable Property. The text editor supports both multiline and single line modes, default is one-line mode.

Since TextField extends AbstractField it implements the Buffered interface. A TextField is in write-through mode by default, so AbstractField.setWriteThrough(boolean) must be called to enable buffering.

Since:
3.0
Version:
5.3.0
Author:
IT Mill Ltd.

Nested Class Summary
 
Nested classes/interfaces inherited from class com.itmill.toolkit.ui.AbstractField
AbstractField.ReadOnlyStatusChangeEvent
 
Nested classes/interfaces inherited from class com.itmill.toolkit.ui.AbstractComponent
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.ui.Field
Field.ValueChangeEvent
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.data.Buffered
Buffered.SourceException
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.data.Property
Property.ConversionException, Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer
 
Constructor Summary
TextField()
          Constructs an empty TextField with no caption.
TextField(Property dataSource)
          Constructs a new TextField that's bound to the specified Property and has no caption.
TextField(String caption)
          Constructs an empty TextField with given caption.
TextField(String caption, Property dataSource)
          Constructs a new TextField that's bound to the specified Property and has the given caption String.
TextField(String caption, String value)
          Constructs a new TextField with the given caption and initial text contents.
 
Method Summary
 void changeVariables(Object source, Map variables)
          Called when one or more variables handled by the implementing class are changed.
 int getColumns()
          Gets the number of columns in the editor.
 Format getFormat()
          Deprecated.  
protected  String getFormattedValue()
          Deprecated.  
 int getMaxLength()
          Returns the maximum number of characters in the field.
 String getNullRepresentation()
          Gets the null-string representation.
 int getRows()
          Gets the number of rows in the editor.
 String getTag()
          Gets the UIDL tag corresponding to the component.
 Class getType()
          Returns the type of the Property.
 Object getValue()
          Gets the current value of the field.
protected  boolean isEmpty()
          Is the field empty?
 boolean isNullSettingAllowed()
          Is setting nulls with null-string representation allowed.
 boolean isSecret()
          Gets the secret property on and off.
 boolean isWordwrap()
          Tests if the editor is in word-wrap mode.
 void paintContent(PaintTarget target)
          Paints any needed component-specific things to the given UIDL stream.
 void setColumns(int columns)
          Sets the number of columns in the editor.
 void setFormat(Format format)
          Deprecated.  
 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 setRows(int rows)
          Sets the number of rows in the editor.
 void setSecret(boolean secret)
          Sets the secret property on and off.
 void setWordwrap(boolean wordwrap)
          Sets the editor's word-wrap mode on or off.
 
Methods inherited from class com.itmill.toolkit.ui.AbstractField
addListener, addListener, addValidator, attach, commit, constructField, discard, fireReadOnlyStatusChange, fireValueChange, focus, getErrorMessage, getPropertyDataSource, getRequiredError, getTabIndex, getValidators, isInvalidAllowed, isInvalidCommitted, isModified, isReadOnly, isReadThrough, isRequired, isValid, isValidationVisible, isWriteThrough, removeListener, removeListener, removeValidator, setCurrentBufferedSourceException, setInternalValue, setInvalidAllowed, setInvalidCommitted, setPropertyDataSource, setReadOnly, setReadThrough, setRequired, setRequiredError, setTabIndex, setValidationVisible, setValue, setValue, setWriteThrough, toString, validate, valueChange
 
Methods inherited from class com.itmill.toolkit.ui.AbstractComponent
addListener, addListener, addListener, addListener, addStyleName, childRequestedRepaint, detach, fireComponentErrorEvent, fireComponentEvent, fireEvent, getApplication, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getHeight, getHeightUnits, getIcon, getLocale, getParent, getStyle, getStyleName, getWidth, getWidthUnits, getWindow, handleError, isEnabled, isImmediate, isVisible, paint, removeListener, removeListener, removeListener, removeListener, removeListener, removeStyleName, requestRepaint, requestRepaintRequests, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setErrorHandler, setHeight, setHeight, setHeight, setHeightUnits, setIcon, setImmediate, setLocale, setParent, setSizeFull, setSizeUndefined, setStyle, setStyleName, setWidth, setWidth, setWidth, setWidthUnits, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.itmill.toolkit.ui.Field
getDescription, setCaption, setDescription
 

Constructor Detail

TextField

public TextField()
Constructs an empty TextField with no caption.


TextField

public TextField(String caption)
Constructs an empty TextField with given caption.

Parameters:
caption - the caption String for the editor.

TextField

public TextField(Property dataSource)
Constructs a new TextField that's bound to the specified Property and has no caption.

Parameters:
dataSource - the Property to be edited with this editor.

TextField

public TextField(String caption,
                 Property dataSource)
Constructs a new TextField that's bound to the specified Property and has the given caption String.

Parameters:
caption - the caption String for the editor.
dataSource - the Property to be edited with this editor.

TextField

public TextField(String caption,
                 String value)
Constructs a new TextField with the given caption and initial text contents. The editor constructed this way will not be bound to a Property unless Property.Viewer.setPropertyDataSource(Property) is called to bind it.

Parameters:
caption - the caption String for the editor.
text - the initial text content of the editor.
Method Detail

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException
Description copied from class: AbstractComponent
Paints any needed component-specific things to the given UIDL stream. The more general AbstractComponent.paint(PaintTarget) method handles all general attributes common to all components, and it calls this method to paint any component-specific attributes to the UIDL stream.

Overrides:
paintContent in class AbstractField
Parameters:
target - the target UIDL stream where the component should paint itself to
Throws:
PaintException - if the paint operation failed.

getFormattedValue

@Deprecated
protected String getFormattedValue()
Deprecated. 

Gets the formatted string value. Sets the field value by using the assigned Format.

Returns:
the Formatted value.
See Also:
setFormat(Format), Format

getValue

public Object getValue()
Description copied from class: AbstractField
Gets the current value of the field.

This is the visible, modified and possible invalid value the user have entered to the field. In the read-through mode, the abstract buffer is also updated and validation is performed.

Note that the object returned is compatible with getType(). For example, if the type is String, this returns Strings even when the underlying datasource is of some other type. In order to access the datasources native type, use getPropertyDatasource().getValue() instead.

Note that when you extend AbstractField, you must reimplement this method if datasource.getValue() is not assignable to class returned by getType() AND getType() is not String. In case of Strings, getValue() calls datasource.toString() instead of datasource.getValue().

Specified by:
getValue in interface Property
Overrides:
getValue in class AbstractField
Returns:
the current value of the field.

getTag

public String getTag()
Description copied from class: AbstractComponent
Gets the UIDL tag corresponding to the component.

Specified by:
getTag in class AbstractComponent
Returns:
the component's UIDL tag as String

changeVariables

public void changeVariables(Object source,
                            Map 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
Overrides:
changeVariables in class AbstractField
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.

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.

getRows

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

Returns:
number of explicitly set rows.

setRows

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

Parameters:
rows - the number of rows for this editor.

isWordwrap

public boolean isWordwrap()
Tests if the editor is in word-wrap mode.

Returns:
true if the component is in the word-wrap mode, false if not.

setWordwrap

public void setWordwrap(boolean wordwrap)
Sets the editor's word-wrap mode on or off.

Parameters:
wordwrap - the boolean value specifying if the editor should be in word-wrap mode after the call or not.

getType

public Class getType()
Description copied from interface: Property
Returns the type of the Property. 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
Specified by:
getType in class AbstractField
Returns:
type of the Property

isSecret

public boolean isSecret()
Gets the secret property on and off. If a field is used to enter secretinformation the information is not echoed to display.

Returns:
true if the field is used to enter secret information, false otherwise.

setSecret

public void setSecret(boolean secret)
Sets the secret property on and off. If a field is used to enter secretinformation the information is not echoed to display.

Parameters:
secret - the value specifying if the field is used to enter secret information.

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 allways 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 allways 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 allways 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 represenation be allways converted to null-values.
See Also:
getNullRepresentation()

getFormat

@Deprecated
public Format getFormat()
Deprecated. 

Gets the value formatter of TextField.

Returns:
the Format used to format the value.

setFormat

@Deprecated
public void setFormat(Format format)
Deprecated. 

Gets the value formatter of TextField.

Parameters:
format - the Format used to format the value. Null disables the formatting.

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

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


Copyright © 2000-2009 IT Mill Ltd. All Rights Reserved.