com.primix.tapestry.valid
Class NumericField

java.lang.Object
  |
  +--com.primix.tapestry.AbstractComponent
        |
        +--com.primix.tapestry.form.AbstractFormComponent
              |
              +--com.primix.tapestry.form.AbstractTextField
                    |
                    +--com.primix.tapestry.valid.AbstractValidatingTextField
                          |
                          +--com.primix.tapestry.valid.NumericField
All Implemented Interfaces:
java.util.EventListener, IComponent, IFormComponent, IRender, IValidatingTextField, PageDetachListener

public class NumericField
extends AbstractValidatingTextField

A Form component that can be used to create a text field that validates that the user has entered a numeric value (if required) and that the value is within a particular range.

When the form is submitted, the result is filtered: If it fails validation, then no update (through the value binding) is performed. Instead, an error flag is set. Also, the invalid text is kept so that it can be the default value for the form element when the page is rendered.

This component doesn't work properly inside a Foreach ... it maintains a little bit of state (invalid text, error flag) that will get confused if the component is re-used on the page.

This single component can be used with any numeric type, it can convert a String to any of the subclasses of Number. It determines the class to convert the String to from the bnding. If the binding is linked to a property of type double (or Double), then the string is converted to Double before being assigned through the binding.

The earlier component, IntegerField, exists for backwards compatibility. It also is a bit more efficient.
Parameter Type Read / Write Required Default Description
value Number R / W yes   The value to be updated. This value will only be read once per request cycle (don't use a NumericField inside a Foreach).

When the form is submitted, this parameter is only updated if the value is valid.

When rendering, a null value will render as the empty string. A value of zero will render normally.

When the form is submitted, the type of the binding is used to determine what kind of object to convert the string to.

minimum Number R no   The minimum value accepted for the field.
maximum Number R no   The maximum value accepted for the field.
required boolean R no false If true, then a non-null value must be provided. If the field is not required, and a null (all whitespace) value is supplied in the field, then the value parameter is not updated.
displayName String R yes   A textual name for the field that is used when formulating error messages.
delegate IValidationDelegate R yes   Object used to assist in error reporting.

May not contain a body. May have informal parameters, which are applied to the underlying TextField.

Version:
$Id: NumericField.java,v 1.4 2001/08/26 04:53:58 hship Exp $
Author:
Howard Ship

Fields inherited from class com.primix.tapestry.AbstractComponent
id, page, specification, wrapped, wrappedCount
 
Constructor Summary
NumericField()
           
 
Method Summary
 IBinding getMaximumBinding()
           
 IBinding getMinimumBinding()
           
 IBinding getValueBinding()
           
protected  java.lang.String read()
          Reads the current value of the text parameter.
 void setMaximumBinding(IBinding value)
           
 void setMinimumBinding(IBinding value)
           
 void setValueBinding(IBinding value)
           
protected  void update(java.lang.String value)
          Takes the String and "sniffs" the value binding to see its type.
 
Methods inherited from class com.primix.tapestry.valid.AbstractValidatingTextField
beforeCloseTag, finishLoad, getDelegate, getDelegateBinding, getDisplayName, getDisplayNameBinding, getError, getRequiredBinding, getString, getString, getString, isRequired, notifyDelegate, pageDetached, readValue, refresh, render, setDelegateBinding, setDisplayNameBinding, setError, setRequiredBinding, updateValue
 
Methods inherited from class com.primix.tapestry.form.AbstractTextField
getDisabledBinding, getDisplayWidthBinding, getHiddenBinding, getMaximumLengthBinding, getName, setDisabledBinding, setDisplayWidthBinding, setHiddenBinding, setMaximumLengthBinding
 
Methods inherited from class com.primix.tapestry.form.AbstractFormComponent
getForm, getForm
 
Methods inherited from class com.primix.tapestry.AbstractComponent
addAsset, addComponent, addWrapped, cleanupAfterRender, cleanupComponent, finishLoad, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, fireObservedChange, generateAttributes, getAsset, getAssets, getBeans, getBinding, getBindingNames, getBindings, getChangeObserver, getComponent, getComponents, getContainer, getExtendedId, getId, getIdPath, getListeners, getPage, getSpecification, prepareForRender, renderWrapped, reset, setBinding, setContainer, setId, setPage, setSpecification, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.primix.tapestry.valid.IValidatingTextField
getName
 
Methods inherited from interface com.primix.tapestry.IComponent
addAsset, addComponent, addWrapped, finishLoad, getAsset, getAssets, getBinding, getBindingNames, getBindings, getComponent, getComponents, getContainer, getExtendedId, getId, getIdPath, getPage, getSpecification, renderWrapped, setBinding, setContainer, setId, setPage, setSpecification
 
Methods inherited from interface com.primix.tapestry.form.IFormComponent
getForm, getName
 

Constructor Detail

NumericField

public NumericField()
Method Detail

getValueBinding

public IBinding getValueBinding()

setValueBinding

public void setValueBinding(IBinding value)

getMinimumBinding

public IBinding getMinimumBinding()

setMinimumBinding

public void setMinimumBinding(IBinding value)

getMaximumBinding

public IBinding getMaximumBinding()

setMaximumBinding

public void setMaximumBinding(IBinding value)

read

protected java.lang.String read()
Reads the current value of the text parameter.
Overrides:
read in class AbstractValidatingTextField

update

protected void update(java.lang.String value)
Takes the String and "sniffs" the value binding to see its type. It then converts the string to that type, does range checks and assigns the value back through the value binding.
Overrides:
update in class AbstractValidatingTextField