Save This Page
Home » commons-validator-1.3.1-src » org.apache.commons » validator » [javadoc | source]
org.apache.commons.validator
public class: Validator [javadoc | source]
java.lang.Object
   org.apache.commons.validator.Validator

All Implemented Interfaces:
    Serializable

Validations are processed by the validate method. An instance of ValidatorResources is used to define the validators (validation methods) and the validation rules for a JavaBean.
Field Summary
public static final  String BEAN_PARAM    Resources key the JavaBean is stored to perform validation on. 
public static final  String VALIDATOR_ACTION_PARAM    Resources key the ValidatorAction is stored under. This will be automatically passed into a validation method with the current ValidatorAction if it is specified in the method signature. 
public static final  String VALIDATOR_RESULTS_PARAM    Resources key the ValidatorResults is stored under. This will be automatically passed into a validation method with the current ValidatorResults if it is specified in the method signature. 
public static final  String FORM_PARAM    Resources key the Form is stored under. This will be automatically passed into a validation method with the current Form if it is specified in the method signature. 
public static final  String FIELD_PARAM    Resources key the Field is stored under. This will be automatically passed into a validation method with the current Field if it is specified in the method signature. 
public static final  String VALIDATOR_PARAM    Resources key the Validator is stored under. This will be automatically passed into a validation method with the current Validator if it is specified in the method signature. 
public static final  String LOCALE_PARAM    Resources key the Locale is stored. This will be used to retrieve the appropriate FormSet and Form to be processed. 
protected  ValidatorResources resources    The Validator Resources. 
protected  String formName    The name of the form to validate 
protected  String fieldName    The name of the field on the form to validate
    since: 1.2.0 -
 
protected  Map parameters    Maps validation method parameter class names to the objects to be passed into the method. 
protected  int page    The current page number to validate. 
protected  ClassLoader classLoader    The class loader to use for instantiating application objects. If not specified, the context class loader, or the class loader used to load Digester itself, is used, based on the value of the useContextClassLoader variable. 
protected  boolean useContextClassLoader    Whether or not to use the Context ClassLoader when loading classes for instantiating new objects. Default is false
protected  boolean onlyReturnErrors    Set this to true to not return Fields that pass validation. Only return failures. 
Constructor:
 public Validator(ValidatorResources resources) 
    Construct a Validator that will use the ValidatorResources passed in to retrieve pluggable validators the different sets of validation rules.
    Parameters:
    resources - ValidatorResources to use during validation.
 public Validator(ValidatorResources resources,
    String formName) 
    Construct a Validator that will use the ValidatorResources passed in to retrieve pluggable validators the different sets of validation rules.
    Parameters:
    resources - ValidatorResources to use during validation.
    formName - Key used for retrieving the set of validation rules.
 public Validator(ValidatorResources resources,
    String formName,
    String fieldName) 
    Construct a Validator that will use the ValidatorResources passed in to retrieve pluggable validators the different sets of validation rules.
    Parameters:
    resources - ValidatorResources to use during validation.
    formName - Key used for retrieving the set of validation rules.
    fieldName - Key used for retrieving the set of validation rules for a field
    since: 1.2.0 -
Method from org.apache.commons.validator.Validator Summary:
clear,   getClassLoader,   getFormName,   getOnlyReturnErrors,   getPage,   getParameterValue,   getUseContextClassLoader,   setClassLoader,   setFieldName,   setFormName,   setOnlyReturnErrors,   setPage,   setParameter,   setUseContextClassLoader,   validate
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.validator.Validator Detail:
 public  void clear() 
    Clears the form name, resources that were added, and the page that was set (if any). This can be called to reinitialize the Validator instance so it can be reused. The form name (key to set of validation rules) and any resources needed, like the JavaBean being validated, will need to set and/or added to this instance again. The ValidatorResources will not be removed since it can be used again and is thread safe.
 public ClassLoader getClassLoader() 
    Return the class loader to be used for instantiating application objects when required. This is determined based upon the following rules:
    • The class loader set by setClassLoader(), if any
    • The thread context class loader, if it exists and the useContextClassLoader property is set to true
    • The class loader used to load the Digester class itself.
 public String getFormName() 
    Gets the form name which is the key to a set of validation rules.
 public boolean getOnlyReturnErrors() 
    Returns true if the Validator is only returning Fields that fail validation.
 public int getPage() 
    Gets the page. This in conjunction with the page property of a Field can control the processing of fields. If the field's page is less than or equal to this page value, it will be processed.
 public Object getParameterValue(String parameterClassName) 
    Returns the value of the specified parameter that will be used during the processing of validations.
 public boolean getUseContextClassLoader() 
    Return the boolean as to whether the context classloader should be used.
 public  void setClassLoader(ClassLoader classLoader) 
    Set the class loader to be used for instantiating application objects when required.
 public  void setFieldName(String fieldName) 
    Sets the name of the field to validate in a form (optional)
 public  void setFormName(String formName) 
    Sets the form name which is the key to a set of validation rules.
 public  void setOnlyReturnErrors(boolean onlyReturnErrors) 
    Configures which Fields the Validator returns from the validate() method. Set this to true to only return Fields that failed validation. By default, validate() returns all fields.
 public  void setPage(int page) 
    Sets the page. This in conjunction with the page property of a Field can control the processing of fields. If the field's page is less than or equal to this page value, it will be processed.
 public  void setParameter(String parameterClassName,
    Object parameterValue) 
    Set a parameter of a pluggable validation method.
 public  void setUseContextClassLoader(boolean use) 
    Determine whether to use the Context ClassLoader (the one found by calling Thread.currentThread().getContextClassLoader()) to resolve/load classes that are defined in various rules. If not using Context ClassLoader, then the class-loading defaults to using the calling-class' ClassLoader.
 public ValidatorResults validate() throws ValidatorException 
    Performs validations based on the configured resources.