org.apache.tapestry.valid
Class NumberValidator

java.lang.Object
  extended by org.apache.tapestry.valid.BaseValidator
      extended by org.apache.tapestry.valid.NumberValidator
All Implemented Interfaces:
IValidator

public class NumberValidator
extends BaseValidator

Simple validation for standard number classes. This is probably insufficient for anything tricky and application specific, such as parsing currency.

Since:
1.0.8
Version:
$Id: NumberValidator.java 243850 2004-03-12 17:13:04Z dsolis $
Author:
Howard Lewis Ship

Nested Class Summary
static class NumberValidator.NumberAdaptor
          This class is not meant for use outside of NumberValidator; it is public only to fascilitate some unit testing.
 
Field Summary
static int NUMBER_TYPE_INTEGER
           
static int NUMBER_TYPE_REAL
           
 
Fields inherited from class org.apache.tapestry.valid.BaseValidator
FIELD_SYMBOL, FORM_SYMBOL, FUNCTION_SYMBOL, VALIDATOR_SYMBOL
 
Constructor Summary
NumberValidator()
           
 
Method Summary
protected  String buildInvalidIntegerFormatMessage(IFormComponent field)
           
protected  String buildInvalidNumericFormatMessage(IFormComponent field)
           
protected  String buildNumberRangeMessage(IFormComponent field)
           
protected  String buildNumberTooLargeMessage(IFormComponent field)
           
protected  String buildNumberTooSmallMessage(IFormComponent field)
           
static NumberValidator.NumberAdaptor getAdaptor(Class type)
          Returns an adaptor for the given type.
 boolean getHasMaximum()
           
 boolean getHasMinimum()
           
 String getInvalidIntegerFormatMessage()
           
 String getInvalidNumericFormatMessage()
           
 Number getMaximum()
           
 Number getMinimum()
           
 String getNumberRangeMessage()
           
 String getNumberTooLargeMessage()
           
 String getNumberTooSmallMessage()
           
 String getScriptPath()
           
 Class getValueTypeClass()
          Returns the value type to convert strings back into.
 boolean getZeroIsNull()
          If true, then when rendering, a zero is treated as a non-value, and null is returned.
 boolean isIntegerNumber()
           
 void renderValidatorContribution(IFormComponent field, IMarkupWriter writer, IRequestCycle cycle)
          This implementation does nothing.
 void setInvalidIntegerFormatMessage(String string)
          Overrides the invalid-int-format bundle key.
 void setInvalidNumericFormatMessage(String string)
          Overrides the invalid-numeric-format bundle key.
 void setMaximum(Number maximum)
           
 void setMinimum(Number minimum)
           
 void setNumberRangeMessage(String string)
          Overrides the number-range bundle key.
 void setNumberTooLargeMessage(String string)
          Overrides the number-too-large bundle key.
 void setNumberTooSmallMessage(String string)
          Overrides the number-too-small bundle key.
 void setScriptPath(String scriptPath)
          Allows a developer to use the existing validation logic with a different client-side script.
 void setValueType(String typeName)
          Sets the value type from a string type name.
 void setValueTypeClass(Class valueTypeClass)
           
 void setZeroIsNull(boolean zeroIsNull)
           
 Object toObject(IFormComponent field, String value)
          Converts input, submitted by the client, into an object value.
 String toString(IFormComponent field, Object value)
          Invoked during rendering to convert an object value (which may be null) to a String.
 
Methods inherited from class org.apache.tapestry.valid.BaseValidator
buildRequiredMessage, checkRequired, formatString, formatString, formatString, getPattern, getRequiredMessage, isClientScriptingEnabled, isRequired, processValidatorScript, setClientScriptingEnabled, setRequired, setRequiredMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUMBER_TYPE_INTEGER

public static final int NUMBER_TYPE_INTEGER
See Also:
Constant Field Values

NUMBER_TYPE_REAL

public static final int NUMBER_TYPE_REAL
See Also:
Constant Field Values
Constructor Detail

NumberValidator

public NumberValidator()
Method Detail

toString

public String toString(IFormComponent field,
                       Object value)
Description copied from interface: IValidator
Invoked during rendering to convert an object value (which may be null) to a String. It is acceptible to return null. The string will be the VALUE attribute of the HTML text field.


getAdaptor

public static NumberValidator.NumberAdaptor getAdaptor(Class type)
Returns an adaptor for the given type.

Note: this method exists only for testing purposes. It is not meant to be invoked by user code and is subject to change at any time.

Parameters:
type - the type (a Number subclass) for which to return an adaptor
Returns:
the adaptor, or null if no such adaptor may be found
Since:
3.0

toObject

public Object toObject(IFormComponent field,
                       String value)
                throws ValidatorException
Description copied from interface: IValidator
Converts input, submitted by the client, into an object value. May return null if the input is null (and the required flag is false).

The input string will already have been trimmed. It may be null.

Throws:
ValidatorException - if the string cannot be converted into an object, or the object is not valid (due to other constraints).

getMaximum

public Number getMaximum()

getHasMaximum

public boolean getHasMaximum()

setMaximum

public void setMaximum(Number maximum)

getMinimum

public Number getMinimum()

getHasMinimum

public boolean getHasMinimum()

setMinimum

public void setMinimum(Number minimum)

getZeroIsNull

public boolean getZeroIsNull()
If true, then when rendering, a zero is treated as a non-value, and null is returned. If false, the default, then zero is rendered as zero.


setZeroIsNull

public void setZeroIsNull(boolean zeroIsNull)

renderValidatorContribution

public void renderValidatorContribution(IFormComponent field,
                                        IMarkupWriter writer,
                                        IRequestCycle cycle)
Description copied from class: BaseValidator
This implementation does nothing. Subclasses may supply their own implementation.

Specified by:
renderValidatorContribution in interface IValidator
Overrides:
renderValidatorContribution in class BaseValidator
Since:
2.2

getScriptPath

public String getScriptPath()
Since:
2.2

setScriptPath

public void setScriptPath(String scriptPath)
Allows a developer to use the existing validation logic with a different client-side script. This is often sufficient to allow application-specific error presentation (perhaps by using DHTML to update the content of a <span> tag, or to use a more sophisticated pop-up window than window.alert()).

Since:
2.2

setValueType

public void setValueType(String typeName)
Sets the value type from a string type name. The name may be a scalar numeric type, a fully qualified class name, or the name of a numeric wrapper type from java.lang (with the package name omitted).

Since:
3.0

setValueTypeClass

public void setValueTypeClass(Class valueTypeClass)
Since:
3.0

getValueTypeClass

public Class getValueTypeClass()
Returns the value type to convert strings back into. The default is int.

Since:
3.0

getInvalidNumericFormatMessage

public String getInvalidNumericFormatMessage()
Since:
3.0

getInvalidIntegerFormatMessage

public String getInvalidIntegerFormatMessage()
Since:
3.0

getNumberRangeMessage

public String getNumberRangeMessage()
Since:
3.0

getNumberTooLargeMessage

public String getNumberTooLargeMessage()
Since:
3.0

getNumberTooSmallMessage

public String getNumberTooSmallMessage()
Since:
3.0

setInvalidNumericFormatMessage

public void setInvalidNumericFormatMessage(String string)
Overrides the invalid-numeric-format bundle key. Parameter {0} is the display name of the field.

Since:
3.0

setInvalidIntegerFormatMessage

public void setInvalidIntegerFormatMessage(String string)
Overrides the invalid-int-format bundle key. Parameter {0} is the display name of the field.

Since:
3.0

buildInvalidNumericFormatMessage

protected String buildInvalidNumericFormatMessage(IFormComponent field)
Since:
3.0

buildInvalidIntegerFormatMessage

protected String buildInvalidIntegerFormatMessage(IFormComponent field)
Since:
3.0

setNumberRangeMessage

public void setNumberRangeMessage(String string)
Overrides the number-range bundle key. Parameter [0} is the display name of the field. Parameter {1} is the minimum value. Parameter {2} is the maximum value.

Since:
3.0

buildNumberRangeMessage

protected String buildNumberRangeMessage(IFormComponent field)

setNumberTooLargeMessage

public void setNumberTooLargeMessage(String string)
Overrides the number-too-large bundle key. Parameter {0} is the display name of the field. Parameter {1} is the maximum allowed value.

Since:
3.0

buildNumberTooLargeMessage

protected String buildNumberTooLargeMessage(IFormComponent field)
Since:
3.0

setNumberTooSmallMessage

public void setNumberTooSmallMessage(String string)
Overrides the number-too-small bundle key. Parameter {0} is the display name of the field. Parameter {1} is the minimum allowed value.

Since:
3.0

buildNumberTooSmallMessage

protected String buildNumberTooSmallMessage(IFormComponent field)
Since:
3.0

isIntegerNumber

public boolean isIntegerNumber()
Since:
3.0