public class Validator extends Object implements Serializable
ValidatorResources
is used to define the validators
(validation methods) and the validation rules for a JavaBean.Modifier and Type | Field and Description |
---|---|
static String |
BEAN_PARAM
Resources key the JavaBean is stored to perform validation on.
|
protected ClassLoader |
classLoader
The class loader to use for instantiating application objects.
|
static String |
FIELD_PARAM
Resources key the
Field is stored under. |
protected String |
fieldName
The name of the field on the form to validate
|
static String |
FORM_PARAM
Resources key the
Form is stored under. |
protected String |
formName
The name of the form to validate
|
static String |
LOCALE_PARAM
Resources key the
Locale is stored. |
protected boolean |
onlyReturnErrors
Set this to true to not return Fields that pass validation.
|
protected int |
page
The current page number to validate.
|
protected Map<String,Object> |
parameters
Maps validation method parameter class names to the objects to be passed
into the method.
|
protected ValidatorResources |
resources
The Validator Resources.
|
protected boolean |
useContextClassLoader
Whether or not to use the Context ClassLoader when loading classes
for instantiating new objects.
|
static String |
VALIDATOR_ACTION_PARAM
Resources key the
ValidatorAction is stored under. |
static String |
VALIDATOR_PARAM
Resources key the
Validator is stored under. |
static String |
VALIDATOR_RESULTS_PARAM
Resources key the
ValidatorResults is stored under. |
Constructor and Description |
---|
Validator(ValidatorResources resources)
Construct a
Validator that will
use the ValidatorResources
passed in to retrieve pluggable validators
the different sets of validation rules. |
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. |
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. |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the form name, resources that were added, and the page that was
set (if any).
|
ClassLoader |
getClassLoader()
Return the class loader to be used for instantiating application objects
when required.
|
String |
getFormName()
Gets the form name which is the key to a set of validation rules.
|
boolean |
getOnlyReturnErrors()
Returns true if the Validator is only returning Fields that fail validation.
|
int |
getPage()
Gets the page.
|
Object |
getParameterValue(String parameterClassName)
Returns the value of the specified parameter that will be used during the
processing of validations.
|
boolean |
getUseContextClassLoader()
Return the boolean as to whether the context classloader should be used.
|
void |
setClassLoader(ClassLoader classLoader)
Set the class loader to be used for instantiating application objects
when required.
|
void |
setFieldName(String fieldName)
Sets the name of the field to validate in a form (optional)
|
void |
setFormName(String formName)
Sets the form name which is the key to a set of validation rules.
|
void |
setOnlyReturnErrors(boolean onlyReturnErrors)
Configures which Fields the Validator returns from the validate() method.
|
void |
setPage(int page)
Sets the page.
|
void |
setParameter(String parameterClassName,
Object parameterValue)
Set a parameter of a pluggable validation method.
|
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. |
ValidatorResults |
validate()
Performs validations based on the configured resources.
|
public static final String BEAN_PARAM
public static final String VALIDATOR_ACTION_PARAM
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
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
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
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
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
Locale
is stored.
This will be used to retrieve the appropriate
FormSet
and Form
to be
processed.protected ValidatorResources resources
protected String formName
protected String fieldName
protected Map<String,Object> parameters
protected int page
protected transient ClassLoader classLoader
useContextClassLoader
variable.protected boolean useContextClassLoader
false
.protected boolean onlyReturnErrors
public Validator(ValidatorResources resources)
Validator
that will
use the ValidatorResources
passed in to retrieve pluggable validators
the different sets of validation rules.resources
- ValidatorResources
to use during validation.public Validator(ValidatorResources resources, String formName)
Validator
that will
use the ValidatorResources
passed in to retrieve pluggable validators
the different sets of validation rules.resources
- ValidatorResources
to use during validation.formName
- Key used for retrieving the set of validation rules.public Validator(ValidatorResources resources, String formName, String fieldName)
Validator
that will
use the ValidatorResources
passed in to retrieve pluggable validators
the different sets of validation rules.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 fieldpublic void setParameter(String parameterClassName, Object parameterValue)
parameterClassName
- The full class name of the parameter of the
validation method that corresponds to the value/instance passed in with it.parameterValue
- The instance that will be passed into the
validation method.public Object getParameterValue(String parameterClassName)
parameterClassName
- The full class name of the parameter of the
validation method that corresponds to the value/instance passed in with it.public String getFormName()
public void setFormName(String formName)
formName
- the name of the form.public void setFieldName(String fieldName)
fieldName
- The name of the field in a form setpublic int getPage()
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 setPage(int 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.
page
- the page number.public void clear()
ValidatorResources
will not be removed since it can be used
again and is thread safe.public boolean getUseContextClassLoader()
public void setUseContextClassLoader(boolean use)
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.use
- determines whether to use Context ClassLoader.public ClassLoader getClassLoader()
setClassLoader()
, if anyuseContextClassLoader
property is set to truepublic void setClassLoader(ClassLoader classLoader)
classLoader
- The new class loader to use, or null
to revert to the standard rulespublic ValidatorResults validate() throws ValidatorException
Map
returned uses the property of the
Field
for the key and the value is the number of error the
field had.ValidatorException
- If an error occurs during validationpublic boolean getOnlyReturnErrors()
public void setOnlyReturnErrors(boolean onlyReturnErrors)
onlyReturnErrors
- whether only failed fields are returned.Copyright © 2002–2017 The Apache Software Foundation. All rights reserved.