com.esri.adf.web.data.tasks.validator
Class NumberValidator

java.lang.Object
  extended by com.esri.adf.web.data.tasks.validator.GenericValidator
      extended by com.esri.adf.web.data.tasks.validator.NumberValidator
All Implemented Interfaces:
TaskParamValidator, Serializable
Direct Known Subclasses:
NumberSpinner

public class NumberValidator
extends GenericValidator

This class is used to define the validation rules to be enforced on a Task parameter which is numeric (byte, short, int, long, float, double, and corresponding Java wrapper classes).

 For Example,
   TaskParamDescriptor paramDescriptor = ...;
   NumberValidator intValidator = new NumberValidator(Integer.class);
   intValidator.setInvalidMessage("Entered number is not valid.");
   intValidator.setPromptMessage("Enter the number between 1 and 99.");
   intValidator.setMinNumber(1);
   intValidator.setMaxNumber(99);
   paramDescriptor.setValidator(intValidator);
 

See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.esri.adf.web.data.tasks.validator.GenericValidator
ADFDOJOTYPE
 
Constructor Summary
NumberValidator(Class<?> numberType)
          Creates a NumberValidator object.
 
Method Summary
 String getRangeMessage()
          Specifies the message to display when the user enters a number that falls outside the permissible range defined by MinNumber and MaxNumber properties.
 void setDecimalDigits(int digits)
          Specifies the number of decimal digits to allow for float and double values.
 void setMaxNumber(double max)
          Specifies the upper bound for the range of permissible values.
 void setMinNumber(double min)
          Specifies the lower bound for the range of permissible values.
 void setRangeMessage(String rangeMessage)
          Specifies the message to display when the user enters a number that falls outside the permissible range defined by MinNumber and MaxNumber properties.
 
Methods inherited from class com.esri.adf.web.data.tasks.validator.GenericValidator
addValidationRule, getInvalidMessage, getPromptMessage, getValidationRules, isRequired, removeValidationRule, setInvalidMessage, setPromptMessage, setRequired
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NumberValidator

public NumberValidator(Class<?> numberType)
Creates a NumberValidator object.
 For Example,
   NumberValidator intNumberValidator = new NumberValidator(Integer.class);
   intNumberValidator.setMinNumber(100);
   intNumberValidator.setMaxNumber(500);
 

Parameters:
numberType - a Java supported numeric type class, like Double, Long etc.
Method Detail

getRangeMessage

public String getRangeMessage()
Specifies the message to display when the user enters a number that falls outside the permissible range defined by MinNumber and MaxNumber properties.

Returns:
String the error message to display.

setRangeMessage

public void setRangeMessage(String rangeMessage)
Specifies the message to display when the user enters a number that falls outside the permissible range defined by MinNumber and MaxNumber properties.

Parameters:
rangeMessage - the error message to display.

setMinNumber

public void setMinNumber(double min)
                  throws IllegalArgumentException
Specifies the lower bound for the range of permissible values. Defaults to the minimum value defined by the validator's number type. For eg, the following validator will have a default MinMumber of Integer.MIN_VALUE .
 NumberValidator intNumberValidator = new NumberValidator(Integer.class);
 

Parameters:
min - the lower bound.
Throws:
IllegalArgumentException - if the specified value is lesser than what the number type permits.

setMaxNumber

public void setMaxNumber(double max)
                  throws IllegalArgumentException
Specifies the upper bound for the range of permissible values. Defaults to the maximum value defined by the validator's number type. For eg, the following validator will have a default MaxNumber of Integer.MAX_VALUE .
 NumberValidator intNumberValidator = new NumberValidator(Integer.class);
 

Parameters:
max - the upper bound.
Throws:
IllegalArgumentException - if the specified value is greater than what the number type permits.

setDecimalDigits

public void setDecimalDigits(int digits)
Specifies the number of decimal digits to allow for float and double values. Default is 2 digits. For example, the following code accepts values such as 100, 100.1, 100.22, 100.333, 100.4444, etc
 NumberValidator doubleNumberValidator = new NumberValidator(Double.class);
 doubleNumberValidator.setMinNumber(100);
 doubleNumberValidator.setMaxNumber(500);
 doubleNumberValidator.setDecimalDigits(4);
 

Parameters:
digits - the number of decimal digits to allow.