org.apache.tapestry.valid
Class NumberValidator

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

public class NumberValidator
extends AbstractNumericValidator

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

Since:
1.0.8
Author:
Howard Lewis Ship

Nested Class Summary
static class NumberValidator.NumberStrategy
          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()
           
NumberValidator(String initializer)
          Initializes the NumberValidator with properties defined by the initializer.
 
Method Summary
protected  String getDefaultScriptPath()
           
 boolean getHasMaximum()
           
 boolean getHasMinimum()
           
 Number getMaximum()
           
 Number getMinimum()
           
static NumberValidator.NumberStrategy getStrategy(Class type)
          Returns an strategy for the given type.
 Class getValueTypeClass()
          Returns the value type to convert strings back into.
 boolean isIntegerNumber()
           
 void renderValidatorContribution(IFormComponent field, IMarkupWriter writer, IRequestCycle cycle)
          This implementation does nothing.
 void setMaximum(Number maximum)
           
 void setMinimum(Number minimum)
           
 void setValueType(String typeName)
          Sets the value type from a string type name.
 void setValueTypeClass(Class valueTypeClass)
           
 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.AbstractNumericValidator
buildInvalidIntegerFormatMessage, buildInvalidNumericFormatMessage, buildNumberRangeMessage, buildNumberTooLargeMessage, buildNumberTooSmallMessage, buildRangeMessage, getInvalidIntegerFormatMessage, getInvalidNumericFormatMessage, getNumberRangeMessage, getNumberTooLargeMessage, getNumberTooSmallMessage, getScriptPath, getZeroIsNull, setInvalidIntegerFormatMessage, setInvalidNumericFormatMessage, setNumberRangeMessage, setNumberTooLargeMessage, setNumberTooSmallMessage, setScriptPath, setZeroIsNull
 
Methods inherited from class org.apache.tapestry.valid.BaseValidator
buildRequiredMessage, checkRequired, formatString, formatString, formatString, getPattern, getRequiredMessage, isClientScriptingEnabled, isRequired, processValidatorScript, setClientScriptingEnabled, setRequired, setRequiredMessage, setScriptSource
 
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()

NumberValidator

public NumberValidator(String initializer)
Initializes the NumberValidator with properties defined by the initializer.

Since:
4.0
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.


getStrategy

public static NumberValidator.NumberStrategy getStrategy(Class type)
Returns an strategy 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)

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

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

isIntegerNumber

public boolean isIntegerNumber()
Since:
3.0

getDefaultScriptPath

protected String getDefaultScriptPath()
Specified by:
getDefaultScriptPath in class AbstractNumericValidator


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.