to.etc.domui.component.input
Class Text<T>

java.lang.Object
  extended by to.etc.domui.dom.css.CssBase
      extended by to.etc.domui.dom.html.NodeBase
          extended by to.etc.domui.dom.html.Input
              extended by to.etc.domui.component.input.Text<T>
All Implemented Interfaces:
IModelBinding, IBindable, IConvertable<T>, INodeErrorDelegate, IActionControl, IControl<T>, IDisplayControl<T>, IHasChangeListener, IHasModifiedIndication, IInputNode<T>
Direct Known Subclasses:
DateInput, HiddenText, TextStr

public class Text<T>
extends Input
implements IInputNode<T>, IHasModifiedIndication, IConvertable<T>

A single-line input box. This extends the "input" tag with validation ability and methods to handle conversions and labels.

Author:
Frits Jalvingh Created on Jun 11, 2008

Nested Class Summary
static class Text.NumberMode
           
 
Constructor Summary
Text(java.lang.Class<T> inputClass)
           
 
Method Summary
 boolean acceptRequestParameter(java.lang.String[] values)
          Handle the input from the request for this component.
 void addValidator(java.lang.Class<? extends IValueValidator<T>> clz)
           
 void addValidator(java.lang.Class<? extends IValueValidator<T>> clz, java.lang.String[] parameters)
           
 void addValidator(IValueValidator<?> v)
           
 void addValidator(PropertyMetaValidator v)
           
 IBinder bind()
          Return the binder for this control.
 void clearMessage()
          Clear message and reset validated flag, so next getValue would result with new validation check.
 IConverter<T> getConverter()
          See IConvertable.getConverter().
 java.lang.Class<T> getInputClass()
          Returns the datatype of the value of this control, as passed in the constructor.
 Text.NumberMode getNumberMode()
          Returns the current numeric mode in effect.
 java.lang.String getRegexpUserString()
           
 java.lang.String getValidationRegexp()
           
 T getValue()
          Returns the current value of this input component.
 T getValueSafe()
          Like IDisplayControl.getValue() this returns the value of the component, but this returns null if the value was invalid.
 boolean hasError()
          Return T if this node currently has an error associated with it.
 boolean isBound()
          Returns T if this control is bound to some data value.
 boolean isMandatory()
          Returns T if this control is mandatory.
 boolean isModified()
          Returns the modified-by-user flag.
 boolean isUntrimmed()
          Returns T if the input is to be left untrimmed.
 void setConverter(IConverter<T> converter)
          See IConvertable.setConverter(IConverter).
 void setMandatory(boolean mandatory)
          Set the control as mandatory.
 void setModified(boolean as)
          Set or clear the modified by user flag.
 void setNumberMode(Text.NumberMode numberMode)
          Sets the current numeric mode in effect.
 void setRegexpUserString(java.lang.String regexpUserString)
           
 void setUntrimmed(boolean untrimmed)
          Specify whether the input is to be space-trimmed before being used.
 void setValidationRegexp(java.lang.String validationRegexp)
           
 void setValue(T value)
          Set a new value in this component.
 boolean validate()
          Main handler to validate input.
 
Methods inherited from class to.etc.domui.dom.html.Input
componentHandleWebAction, getInputType, getMaxLength, getOnKeyPressJS, getOnLookupTyping, getOnValueChanged, getRawValue, getSize, isDisabled, isReadOnly, setDisabled, setMaxLength, setOnKeyPressJS, setOnLookupTyping, setOnValueChanged, setRawValue, setReadOnly, setSize, visit
 
Methods inherited from class to.etc.domui.dom.html.NodeBase
$, addCssClass, addGlobalMessage, afterCreateContent, appendAfterMe, appendBeforeMe, appendCreateJS, appendJavascript, build, changed, clearFocusRequested, clearGlobalMessage, clearGlobalMessage, clearGlobalMessage, createContent, findComponentBundle, forceRebuild, getActualID, getClicked, getComponentBundle, getCreateJS, getCssClass, getErrorDelegate, getErrorLocation, getMessage, getOnClickJS, getOnMouseDownJS, getPage, getParent, getParent, getParent, getSharedContext, getSpecialAttribute, getSpecialAttributeList, getTag, getTestID, getTitle, getUserObject, handleDrop, hasCssClass, internalClearDelta, internalClearDeltaFully, internalGetOldParent, internalHasChangedAttributes, internalNeedClickHandler, internalOnClicked, internalSetHasChangedAttributes, internalSetHasChangedAttributes, internalSetTag, internalShelve, internalUnshelve, isBuilt, isFocusRequested, moveControlToModel, moveModelToControl, onAddedToPage, onBeforeFullRender, onForceRebuild, onHeaderContributors, onRefresh, onRemoveFromPage, onShelve, onUnshelve, refresh, remove, removeCssClass, renderJavascriptState, replaceWith, setClicked, setComponentBundle, setControlsEnabled, setCssClass, setErrorDelegate, setErrorLocation, setFocus, setMessage, setOnClickJS, setOnMouseDownJS, setSpecialAttribute, setTestID, setTitle, setUserObject, stretchHeight, toString
 
Methods inherited from class to.etc.domui.dom.css.CssBase
getBackgroundAttachment, getBackgroundColor, getBackgroundImage, getBackgroundPosition, getBackgroundRepeat, getBorderBottomColor, getBorderBottomStyle, getBorderBottomWidth, getBorderLeftColor, getBorderLeftStyle, getBorderLeftWidth, getBorderRightColor, getBorderRightStyle, getBorderRightWidth, getBorderTopColor, getBorderTopStyle, getBorderTopWidth, getBottom, getCachedStyle, getClear, getColor, getDisplay, getFloat, getFontFamily, getFontSize, getFontSizeAdjust, getFontStyle, getFontVariant, getFontWeight, getHeight, getLeft, getLineHeight, getMarginBottom, getMarginLeft, getMarginRight, getMarginTop, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOverflow, getPosition, getRight, getTextAlign, getTop, getTransform, getVerticalAlign, getVisibility, getWidth, getZIndex, internalSetDisplay, setBackgroundAttachment, setBackgroundColor, setBackgroundImage, setBackgroundPosition, setBackgroundRepeat, setBorder, setBorder, setBorderBottomColor, setBorderBottomStyle, setBorderBottomWidth, setBorderColor, setBorderLeftColor, setBorderLeftStyle, setBorderLeftWidth, setBorderRightColor, setBorderRightStyle, setBorderRightWidth, setBorderStyle, setBorderTopColor, setBorderTopStyle, setBorderTopWidth, setBorderWidth, setBottom, setBottom, setCachedStyle, setClear, setColor, setDisplay, setFloat, setFontFamily, setFontSize, setFontSizeAdjust, setFontStyle, setFontVariant, setFontWeight, setHeight, setLeft, setLeft, setLineHeight, setMargin, setMarginBottom, setMarginLeft, setMarginRight, setMarginTop, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setOverflow, setPosition, setRight, setRight, setTextAlign, setTop, setTop, setTransform, setVerticalAlign, setVisibility, setWidth, setZIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface to.etc.domui.dom.html.IControl
getErrorLocation, isDisabled, isReadOnly, setErrorLocation, setReadOnly
 
Methods inherited from interface to.etc.domui.dom.html.IDisplayControl
setTestID
 
Methods inherited from interface to.etc.domui.dom.html.IActionControl
setDisabled, setTestID
 
Methods inherited from interface to.etc.domui.dom.html.IHasChangeListener
getOnValueChanged, setOnValueChanged
 
Methods inherited from interface to.etc.domui.dom.errors.INodeErrorDelegate
getMessage, setMessage
 

Constructor Detail

Text

public Text(java.lang.Class<T> inputClass)
Method Detail

acceptRequestParameter

public boolean acceptRequestParameter(java.lang.String[] values)
Handle the input from the request for this component.

Overrides:
acceptRequestParameter in class Input
See Also:
Input.acceptRequestParameter(java.lang.String[])

validate

public boolean validate()
Main handler to validate input. This gets called whenever new input is present in the control (unvalidated) and: If validation fails it sets this control in ERROR status, and it registers the error message into the Page. When in ERROR state an input control will add an "invalidValue" class to it's HTML class, and it may expose error labels on it.


getInputClass

public java.lang.Class<T> getInputClass()
Returns the datatype of the value of this control, as passed in the constructor.

Returns:

getConverter

public IConverter<T> getConverter()
See IConvertable.getConverter(). This returns null if no converter has been set. It also returns null if a default converter is used.

Specified by:
getConverter in interface IConvertable<T>
Returns:

setConverter

public void setConverter(IConverter<T> converter)
See IConvertable.setConverter(IConverter). Sets the Converter to use to convert the string value to a T and vice versa. It is the programmer's responsibility to ensure that the converter actually converts to a T; if not the code will throw ClassCastExceptions.

Specified by:
setConverter in interface IConvertable<T>
Parameters:
converter -

getValue

public T getValue()
Description copied from interface: IDisplayControl
Returns the current value of this input component. If the component contains no value this returns null. All text input components will return null when their value is the empty string! If the component, during conversion or validation of the input value, discovers that the input is invalid it will set itself in "error" mode, post an error message up the form, and throw a ValidationException. This means that this call either delivers correct input (as defined by it's converter and validators), null (when empty) or throws an exception. When a ValidationException occurs the framework mostly ignores it - it does not produce a stacktrace or error in the client. Instead the resulting error as posted by the error handling framework gets displayed on the form when the request completes.

To get the value of a component while ignoring exceptions call #getValueSafe().

Specified by:
getValue in interface IDisplayControl<T>
Returns:
See Also:
IDisplayControl.getValue()

clearMessage

public void clearMessage()
Clear message and reset validated flag, so next getValue would result with new validation check.

Specified by:
clearMessage in interface INodeErrorDelegate
Overrides:
clearMessage in class NodeBase
See Also:
NodeBase.clearMessage()

getValueSafe

public T getValueSafe()
Description copied from interface: IControl
Like IDisplayControl.getValue() this returns the value of the component, but this returns null if the value was invalid. For this method NULL either means the value was invalid OR it's content was empty. To distinguish between the two call IControl.hasError() or use IDisplayControl.getValue() instead of this call.

Specified by:
getValueSafe in interface IControl<T>
Returns:
See Also:
IControl.getValueSafe()

hasError

public boolean hasError()
Description copied from class: NodeBase
Return T if this node currently has an error associated with it.

Specified by:
hasError in interface IControl<T>
Overrides:
hasError in class NodeBase
Returns:
See Also:
IControl.hasError()

setValue

public void setValue(T value)
Set a new value in this component. The value will be converted to a string representation by any converter set or by one of the default converters. This string value will then be shown to the users.

Specified by:
setValue in interface IDisplayControl<T>
See Also:
IDisplayControl.setValue(java.lang.Object)

isMandatory

public boolean isMandatory()
Returns T if this control is mandatory.

Specified by:
isMandatory in interface IControl<T>
Returns:
See Also:
IControl.isMandatory()

setMandatory

public void setMandatory(boolean mandatory)
Set the control as mandatory. A mandatory control expects the value filled in to be non-whitespace.

Specified by:
setMandatory in interface IControl<T>
See Also:
IControl.setMandatory(boolean)

isUntrimmed

public boolean isUntrimmed()
Returns T if the input is to be left untrimmed.

Returns:

setUntrimmed

public void setUntrimmed(boolean untrimmed)
Specify whether the input is to be space-trimmed before being used. This defaults to TRUE, causing values to be trimmed before being returned to the converter code.

Parameters:
untrimmed -

getNumberMode

public Text.NumberMode getNumberMode()
Returns the current numeric mode in effect. This mode prevents letters from being input on the screen.

Returns:

setNumberMode

public void setNumberMode(Text.NumberMode numberMode)
Sets the current numeric mode in effect. This mode prevents letters from being input on the screen.

Parameters:
numberMode -

addValidator

public void addValidator(IValueValidator<?> v)

addValidator

public void addValidator(PropertyMetaValidator v)

addValidator

public void addValidator(java.lang.Class<? extends IValueValidator<T>> clz)

addValidator

public void addValidator(java.lang.Class<? extends IValueValidator<T>> clz,
                         java.lang.String[] parameters)

getValidationRegexp

public java.lang.String getValidationRegexp()

setValidationRegexp

public void setValidationRegexp(java.lang.String validationRegexp)

getRegexpUserString

public java.lang.String getRegexpUserString()

setRegexpUserString

public void setRegexpUserString(java.lang.String regexpUserString)

isModified

public boolean isModified()
Returns the modified-by-user flag.

Specified by:
isModified in interface IHasModifiedIndication
See Also:
IHasModifiedIndication.isModified()

setModified

public void setModified(boolean as)
Set or clear the modified by user flag.

Specified by:
setModified in interface IHasModifiedIndication
See Also:
IHasModifiedIndication.setModified(boolean)

bind

public IBinder bind()
Return the binder for this control.

Specified by:
bind in interface IBindable
Returns:
See Also:
IBindable.bind()

isBound

public boolean isBound()
Returns T if this control is bound to some data value.

Specified by:
isBound in interface IBindable
Returns:
See Also:
IBindable.isBound()