org.apache.shale.validator.validator
Class AbstractValidator

java.lang.Object
  extended by org.apache.shale.validator.util.AbstractUtilities
      extended by org.apache.shale.validator.validator.AbstractValidator
All Implemented Interfaces:
EventListener, javax.faces.component.StateHolder, javax.faces.validator.Validator
Direct Known Subclasses:
DoubleValidator, FloatValidator, IntegerValidator, LongValidator, ShortValidator

public abstract class AbstractValidator
extends AbstractUtilities
implements javax.faces.validator.Validator

Abstract base class for validators that use Apache Commons Validator as their foundation.


Field Summary
protected static String ARG_VALUE
          Variable name in a vars map representing the argument that was being evaluated, and should be included in any error message.
protected static org.apache.shale.util.ConverterHelper helper
          Converter helper instance we can use in the convert() method implementation.
protected static String MAXIMUM_VALUE
          Variable name in a vars map representing the maximum value that should be accepted by this Validator.
protected static String MINIMUM_VALUE
          Variable name in a vars map representing the minimum value that should be accepted by this Validator.
protected static String SUBMITTED_VALUE
          Variable name in a vars map representing the submitted value that should be validated by this Validator.
 
Fields inherited from class org.apache.shale.validator.util.AbstractUtilities
DEFAULT_RESOURCE_BUNDLE
 
Fields inherited from interface javax.faces.validator.Validator
NOT_IN_RANGE_MESSAGE_ID
 
Constructor Summary
AbstractValidator()
           
 
Method Summary
protected  ShaleValidatorAction[] actions(javax.faces.context.FacesContext context, String type)
          Return an array of ShaleValidatorActions to execute for a given validation, starting with the configured dependent actions, and ending with the action corresponding to the specified action type.
protected  Object convert(javax.faces.context.FacesContext context, Object value, Class type)
          Use the registered converters to convert the specified value to the specified type.
 boolean isClient()
          Return a flag describing whether this validator should be enforced on the client side or not.
protected  ValidatorResources resources(javax.faces.context.FacesContext context)
          Return the ValidatorResources that describe the validation rules to be enforced by this application.
 void restoreState(javax.faces.context.FacesContext context, Object state)
          
 Object saveState(javax.faces.context.FacesContext context)
          
 void setClient(boolean client)
          Set a flag describing whether this validator should be enforced on the client side or not.
abstract  void validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
          Perform the correctness checks implemented by this Validator against the specified UIComponent.
protected  void validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value, String type, Map vars)
          Perform a validation using the specified Commons Validator type.
 
Methods inherited from class org.apache.shale.validator.util.AbstractUtilities
getMessage, isTransient, message, message, message, setMessage, setTransient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARG_VALUE

protected static final String ARG_VALUE

Variable name in a vars map representing the argument that was being evaluated, and should be included in any error message. Typically, this will be either the value itself or a user-friendly (localized) field label.

See Also:
Constant Field Values

MAXIMUM_VALUE

protected static final String MAXIMUM_VALUE

Variable name in a vars map representing the maximum value that should be accepted by this Validator.

See Also:
Constant Field Values

MINIMUM_VALUE

protected static final String MINIMUM_VALUE

Variable name in a vars map representing the minimum value that should be accepted by this Validator.

See Also:
Constant Field Values

SUBMITTED_VALUE

protected static final String SUBMITTED_VALUE

Variable name in a vars map representing the submitted value that should be validated by this Validator.

See Also:
Constant Field Values

helper

protected static final org.apache.shale.util.ConverterHelper helper

Converter helper instance we can use in the convert() method implementation.

Constructor Detail

AbstractValidator

public AbstractValidator()
Method Detail

isClient

public boolean isClient()

Return a flag describing whether this validator should be enforced on the client side or not. Default is true.


setClient

public void setClient(boolean client)

Set a flag describing whether this validator should be enforced on the client side or not.

Parameters:
client - The new client enforcement flag

validate

public abstract void validate(javax.faces.context.FacesContext context,
                              javax.faces.component.UIComponent component,
                              Object value)
                       throws javax.faces.validator.ValidatorException

Perform the correctness checks implemented by this Validator against the specified UIComponent. If any violations are found, a ValidatorException will be thrown containing the FacesMessage describing the failure.

IMPLEMENTATION NOTE: Unlike earlier implementations of Shale Validator integration, validators that subclass this class do not support the option to skip server side validation.

Specified by:
validate in interface javax.faces.validator.Validator
Parameters:
context - FacesContext for the current request
component - UIComponent we are checking for correctness
value - The value to validate
Throws:
javax.faces.validator.ValidatorException - if validation fails
NullPointerException - if context or component is null

restoreState

public void restoreState(javax.faces.context.FacesContext context,
                         Object state)

Specified by:
restoreState in interface javax.faces.component.StateHolder
Overrides:
restoreState in class AbstractUtilities

saveState

public Object saveState(javax.faces.context.FacesContext context)

Specified by:
saveState in interface javax.faces.component.StateHolder
Overrides:
saveState in class AbstractUtilities

actions

protected ShaleValidatorAction[] actions(javax.faces.context.FacesContext context,
                                         String type)

Return an array of ShaleValidatorActions to execute for a given validation, starting with the configured dependent actions, and ending with the action corresponding to the specified action type. If there is no defined action with the specified type, return null.

Parameters:
context - FacesContext for the current request
type - Type of the validator action for which to return actions

convert

protected Object convert(javax.faces.context.FacesContext context,
                         Object value,
                         Class type)

Use the registered converters to convert the specified value to the specified type.

Parameters:
context - FacesContext for the current request
value - Value to be converted
type - Type to which the value should be converted

resources

protected ValidatorResources resources(javax.faces.context.FacesContext context)

Return the ValidatorResources that describe the validation rules to be enforced by this application.

Parameters:
context - FacesContext for the current request

validate

protected void validate(javax.faces.context.FacesContext context,
                        javax.faces.component.UIComponent component,
                        Object value,
                        String type,
                        Map vars)
                 throws javax.faces.validator.ValidatorException

Perform a validation using the specified Commons Validator type.

Parameters:
context - FacesContext for the current request
component - UIComponent whose value is being validated
value - The value being validated
type - Type of validation to be performed
vars - Mutable map of values to be passed in to the validation
Throws:
javax.faces.validator.ValidatorException - if a validation error occurs


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.