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

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

public class GenericValidator
extends Object
implements TaskParamValidator, Serializable

GenericValidator is an implementation of the TaskParamValidator interface and helps to provide validation in the ADF Task framework. A Task contains parameters, actions, and tools. When a Task is rendered on a web page, the parameters are rendered as form fields to capture user input. Parameter values entered by the user can be validated using validators provided by the Task framework. The validators are java classes, but they emit javascript to perform validation on the browser using the DOJO Javascript library.

GenericValidator is an unstructed validator and is a super class of structured validators like StringValidator, DateValidator, NumberValidator, and NumberSpinner. The structured validators are specifically designed for their corresponding data type and provide validation rules relevant to the data type. You should use structed validators wherever possible.

GenericValidator can be useful for validating data types not supported by the structured validators but available in the DOJO library. For example, the following code shows how to use the GenericValidator to validate a value representing currency :

   TaskParamDescriptor paramDescriptor = ...;
   GenericValidator validator = new GenericValidator();
   validator.addValidationRule(GenericValidator.ADFDOJOTYPE, "adfdijit.form.CurrencyTextBox");
   validator.addValidationRule("constraints", "{fractional:true}");
   validator.addValidationRule("currency", "USD");
   validator.setPromptMessage("Enter price in USD.");
   paramDescriptor.setValidator(validator);
 

See Also:
Serialized Form

Field Summary
static String ADFDOJOTYPE
          Key used to stores the ADF Dojo Dijit type string, it is upon subclass implementing it.
 
Constructor Summary
GenericValidator()
           
 
Method Summary
 void addValidationRule(String key, String value)
          Validation rules are key-value pairs which are set as attributes on DOJO dijits to validate the parameter.
 String getInvalidMessage()
          Returns the message that will be displayed to the user when the parameter's value does not pass the validation rules.
 String getPromptMessage()
          Returns the message that will be displayed to the user when the parameter acquires focus on the web page.
 Properties getValidationRules()
          Returns a Properties object which defines a set of property/value pair to validate the user input.
 boolean isRequired()
          Specifies whether a value is mandatory for the parameter.
 void removeValidationRule(String key)
          Removes the specified key if there is one exist in the validation rule.
 void setInvalidMessage(String invalidMessage)
          Specifies the message that will be displayed to the user when the parameter's value does not pass the validation rules
 void setPromptMessage(String promptMessage)
          Specifies the message that will be displayed to the user when the parameter acquires focus on the web page.
 void setRequired(boolean required)
          Specifies whether a value is mandatory for the parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ADFDOJOTYPE

public static final String ADFDOJOTYPE
Key used to stores the ADF Dojo Dijit type string, it is upon subclass implementing it.

See Also:
Constant Field Values
Constructor Detail

GenericValidator

public GenericValidator()
Method Detail

getValidationRules

public Properties getValidationRules()
Returns a Properties object which defines a set of property/value pair to validate the user input.

Specified by:
getValidationRules in interface TaskParamValidator
Returns:
the validation object.

addValidationRule

public void addValidationRule(String key,
                              String value)
Validation rules are key-value pairs which are set as attributes on DOJO dijits to validate the parameter. Structured validators like StringValidator, DateValidator, NumberValidator, and NumberSpinner provide convenient methods to set validation rules. You will typically only use this method when you want to set a validation rule not supported by those validators. Refer the DOJO documentation on http://docs.dojocampus.org for more information on which attributes are supported by which dijits.

For example, the following code

 GenericValidator validator = new GenericValidator();
 validator.addValidationRule(GenericValidator.ADFDOJOTYPE, "adfdijit.form.CurrencyTextBox");
 validator.addValidationRule("constraints", "{fractional:true}");
 validator.addValidationRule("currency", "USD");
 
renders the following HTML
 <input type="TEXT" adfdojoType="adfdijit.form.CurrencyTextBox" constraints="{fractional:true}" currency="USD">
 


removeValidationRule

public void removeValidationRule(String key)
Removes the specified key if there is one exist in the validation rule.


getInvalidMessage

public String getInvalidMessage()
Returns the message that will be displayed to the user when the parameter's value does not pass the validation rules.

Returns:
the message.

setInvalidMessage

public void setInvalidMessage(String invalidMessage)
Specifies the message that will be displayed to the user when the parameter's value does not pass the validation rules

Parameters:
invalidMessage - the message.

getPromptMessage

public String getPromptMessage()
Returns the message that will be displayed to the user when the parameter acquires focus on the web page.

Returns:
the message.

setPromptMessage

public void setPromptMessage(String promptMessage)
Specifies the message that will be displayed to the user when the parameter acquires focus on the web page.

Parameters:
promptMessage - the message.

isRequired

public boolean isRequired()
Specifies whether a value is mandatory for the parameter. If a value is not provided, the parameter will be flagged with a warning indicator on the web page. By default, the value is not required.

Returns:
true, if the input value is mandatory.

setRequired

public void setRequired(boolean required)
Specifies whether a value is mandatory for the parameter. If a value is not provided, the parameter will be flagged with a warning indicator on the web page. By default, the value is not required.

Parameters:
required - true, if the input value is mandatory.