org.apache.myfaces.extensions.validator.core.interceptor
Class AbstractValidationInterceptor

java.lang.Object
  extended by org.apache.myfaces.extensions.validator.core.interceptor.AbstractRendererInterceptor
      extended by org.apache.myfaces.extensions.validator.core.interceptor.AbstractValidationInterceptor
All Implemented Interfaces:
RendererInterceptor
Direct Known Subclasses:
BeanValidationModuleValidationInterceptor, ValidationInterceptor

public abstract class AbstractValidationInterceptor
extends AbstractRendererInterceptor

A basic implementation of RendererInterceptor for validating fields. It adds some extension point for subclasses and performs tasks like :
- storing field values (recordProcessedInformation())
- resetting required information property UIComponent
- calling before and after Validation interceptors
- etc ...

Since:
x.x.3
Author:
Gerhard Petracek

Field Summary
 
Fields inherited from class org.apache.myfaces.extensions.validator.core.interceptor.AbstractRendererInterceptor
logger
 
Constructor Summary
AbstractValidationInterceptor()
           
 
Method Summary
 void afterDecode(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, javax.faces.render.Renderer wrapped)
          Sets required property of UIComponent to false after decoding.
 void beforeEncodeBegin(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, javax.faces.render.Renderer wrapped)
          Before the component gets rendered the interceptor initializes the component based on the meta-data which is provided by the referenced property (if component initialization is activated).
 void beforeGetConvertedValue(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, Object o, javax.faces.render.Renderer wrapped)
          The method performs the validation of the field and calls the registered interceptors regarding the validation.
protected abstract  MetaDataExtractor getComponentMetaDataExtractor(Map<String,Object> properties)
          Implementations must return the MetaDataExtractor that will perform the extraction of the meta data from the component.
protected  ELHelper getELHelper()
          Returns the ELHelper to be used in the process of the validation.
protected  Map<String,Object> getInterceptorProperties(javax.faces.component.UIComponent uiComponent)
          Create the properties which can be used by a MetaDataExtractor.
protected  Class getModuleKey()
          Identification of the validation module.
protected  Map<String,Object> getPropertiesForComponentMetaDataExtractor(javax.faces.component.UIComponent uiComponent)
          Create the properties which can be used by a MetaDataExtractor.
protected  PropertyInformation getPropertyInformation(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent)
          Extrancts the PropertyInformation for the given component.
protected abstract  void initComponent(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent)
          Initialize the component based on the meta-data which is provided by the referenced property.
protected  boolean interpretEmptyStringValuesAsNull()
          Uses a config parameter (javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL) which was introduced by JSF 2 for converting empty strings to null.
protected  boolean isRequiredInitializationSupported()
          In case of required initialization it's needed for some use-cases to reset the (required-)state of the components.
protected  boolean isValueToValidateEmpty(Object convertedObject)
          Defines if a value is empty.
protected  void processAfterValidation(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, Object value)
          Execute the afterValidation method of the registered PropertyValidationInterceptor's.
protected  boolean processBeforeValidation(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, Object value)
          Execute the beforeValidation method of the registered PropertyValidationInterceptor's.
protected  boolean processComponent(javax.faces.component.UIComponent uiComponent)
          Based on basic rules the method checks if the current component should be processed.
protected abstract  void processValidation(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, Object convertedObject)
          A concrete implementation has to perform the actual validation of the value.
protected  boolean recordProcessedInformation()
          Signals if the converted value should be stored e.g. for the cross-validation process.
protected  Object transformValueForValidation(Object convertedObject)
          Converts an empty String to null when the parameter interpretEmptyStringValuesAsNull is set.
protected  boolean validateEmptyFields()
          Uses a config parameter (javax.faces.VALIDATE_EMPTY_FIELDS) which was introduced by JSF 2 for deactivating the validation of empty fields.
protected  boolean validateValue(Object convertedObject)
          Evaluates if the value should be validated in case it is empty (null or no characters).
 
Methods inherited from class org.apache.myfaces.extensions.validator.core.interceptor.AbstractRendererInterceptor
afterEncodeBegin, afterEncodeChildren, afterEncodeEnd, afterGetConvertedValue, beforeDecode, beforeEncodeChildren, beforeEncodeEnd, getInterceptorId, getReturnValueOnSkipRendererDelegationException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractValidationInterceptor

public AbstractValidationInterceptor()
Method Detail

isRequiredInitializationSupported

protected boolean isRequiredInitializationSupported()
In case of required initialization it's needed for some use-cases to reset the (required-)state of the components. Such a reset is just needed if required initialization is activated.

Returns:
true if required initialization is supported by the current implementation, false otherwise

afterDecode

public void afterDecode(javax.faces.context.FacesContext facesContext,
                        javax.faces.component.UIComponent uiComponent,
                        javax.faces.render.Renderer wrapped)
                 throws SkipAfterInterceptorsException
Sets required property of UIComponent to false after decoding. It's needed for special use-cases if required initialization is supported. The final required validation will be done by the corresponding constraint validator. Intercepts a method of the renderer. The name of the intercepted method is the name of this method without the prefix ('after').

Specified by:
afterDecode in interface RendererInterceptor
Overrides:
afterDecode in class AbstractRendererInterceptor
Parameters:
facesContext - The JSF Context
uiComponent - The current component
wrapped - The intercepted renderer
Throws:
SkipAfterInterceptorsException - Can be thrown to stop the execution of the subsequent interceptors.

beforeEncodeBegin

public void beforeEncodeBegin(javax.faces.context.FacesContext facesContext,
                              javax.faces.component.UIComponent uiComponent,
                              javax.faces.render.Renderer wrapped)
                       throws IOException,
                              SkipBeforeInterceptorsException,
                              SkipRendererDelegationException
Before the component gets rendered the interceptor initializes the component based on the meta-data which is provided by the referenced property (if component initialization is activated). Intercepts a method of the renderer. The name of the intercepted method is the name of this method without the prefix ('before').

Specified by:
beforeEncodeBegin in interface RendererInterceptor
Overrides:
beforeEncodeBegin in class AbstractRendererInterceptor
Parameters:
facesContext - The JSF Context
uiComponent - The current component
wrapped - The intercepted renderer
Throws:
IOException - In case the response writer is accessed and there was an IO problem.
SkipBeforeInterceptorsException - can be thrown to stop the execution of the subsequent interceptors
SkipRendererDelegationException - can be thorwn to skip the invocation of the intercepted renderer method.

initComponent

protected abstract void initComponent(javax.faces.context.FacesContext facesContext,
                                      javax.faces.component.UIComponent uiComponent)
Initialize the component based on the meta-data which is provided by the referenced property.

Parameters:
facesContext - The JSF Context
uiComponent - The component which is processed

beforeGetConvertedValue

public void beforeGetConvertedValue(javax.faces.context.FacesContext facesContext,
                                    javax.faces.component.UIComponent uiComponent,
                                    Object o,
                                    javax.faces.render.Renderer wrapped)
                             throws javax.faces.convert.ConverterException,
                                    SkipBeforeInterceptorsException,
                                    SkipRendererDelegationException
The method performs the validation of the field and calls the registered interceptors regarding the validation. The main steps are :
- Get the converted value from the renderer (possibly cached by the RendererProxy)
- Record the value (e.g. for cross validation)
- Adjust the converted value for interpret empty values as null.
- Execute the beforeValidation method of the registered PropertyValidationInterceptor's.
- Perform the validation when the PropertyValidationInterceptor have indicate it that it should be performed.
- When a validation error occurred, ask the ViolationSeverityInterpreter if this validation should result in an exception
- Execute the afterValidation method of the registered PropertyValidationInterceptor's. (when validation actually tooks place) Intercepts a method of the renderer. The name of the intercepted method is the name of this method without the prefix ('before').

Specified by:
beforeGetConvertedValue in interface RendererInterceptor
Overrides:
beforeGetConvertedValue in class AbstractRendererInterceptor
Parameters:
facesContext - The JSF Context
uiComponent - The current component
o - The submitted value
wrapped - The intercepted renderer
Throws:
javax.faces.convert.ConverterException - ExtVal validation strategies can throw ValidatorExceptions. Due to the trick used by ExtVal it has to be converted to a ConverterException (see AbstractValidationInterceptor).
SkipBeforeInterceptorsException - can be thrown to stop the execution of the subsequent interceptors
SkipRendererDelegationException - can be thorwn to skip the invocation of the intercepted renderer method.

processBeforeValidation

protected boolean processBeforeValidation(javax.faces.context.FacesContext facesContext,
                                          javax.faces.component.UIComponent uiComponent,
                                          Object value)
Execute the beforeValidation method of the registered PropertyValidationInterceptor's.

Parameters:
facesContext - The JSF Context
uiComponent - The UIComponent which is processed.
value - The value to validate
Returns:
true when validation can proceed, false otherwise.

processAfterValidation

protected void processAfterValidation(javax.faces.context.FacesContext facesContext,
                                      javax.faces.component.UIComponent uiComponent,
                                      Object value)
Execute the afterValidation method of the registered PropertyValidationInterceptor's.

Parameters:
facesContext - The JSF Context
uiComponent - The UIComponent which is processed.
value - The value which has just been validated.

getPropertyInformation

protected PropertyInformation getPropertyInformation(javax.faces.context.FacesContext facesContext,
                                                     javax.faces.component.UIComponent uiComponent)
Extrancts the PropertyInformation for the given component.

Parameters:
facesContext - The JSF Context
uiComponent - The UIComponent which is processed.
Returns:
the information of the referenced property (e.g. base object, property name, meta-data, ...)

getComponentMetaDataExtractor

protected abstract MetaDataExtractor getComponentMetaDataExtractor(Map<String,Object> properties)
Implementations must return the MetaDataExtractor that will perform the extraction of the meta data from the component. The component itself is present in the properties map (it might influence the type of the returned MetaDataExtractor.

Parameters:
properties - Properties that can be used to determine the extractor which is returned.
Returns:
The MetaDataExtractor used for performing the xtraction of the meta data from the component.

transformValueForValidation

protected Object transformValueForValidation(Object convertedObject)
Converts an empty String to null when the parameter interpretEmptyStringValuesAsNull is set.

Parameters:
convertedObject - Converted objected
Returns:
Adjusted value that should be used from now on as converted value.

validateValue

protected boolean validateValue(Object convertedObject)
Evaluates if the value should be validated in case it is empty (null or no characters). ExtVal also uses a config parameter introduced by JSF 2 which allows to skip the validation of empty fields.

Parameters:
convertedObject - The converted value.
Returns:
true if the given value should be validated, false otherwise

isValueToValidateEmpty

protected boolean isValueToValidateEmpty(Object convertedObject)
Defines if a value is empty. The definition of empty is that it is null or has no characters in the String value.

Parameters:
convertedObject - The converted value.
Returns:
true if the given value is the representation of an empty value

validateEmptyFields

protected boolean validateEmptyFields()
Uses a config parameter (javax.faces.VALIDATE_EMPTY_FIELDS) which was introduced by JSF 2 for deactivating the validation of empty fields.

Returns:
true if the validation of empty fields is enabled, false otherwise

interpretEmptyStringValuesAsNull

protected boolean interpretEmptyStringValuesAsNull()
Uses a config parameter (javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL) which was introduced by JSF 2 for converting empty strings to null.

Returns:
true if an empty string should be replaced with null (for the validation process), false otherwise

processValidation

protected abstract void processValidation(javax.faces.context.FacesContext facesContext,
                                          javax.faces.component.UIComponent uiComponent,
                                          Object convertedObject)
A concrete implementation has to perform the actual validation of the value.

Parameters:
facesContext - The JSF Context
uiComponent - The UIComponent which is processed.
convertedObject - The (adjusted) converted value.

processComponent

protected boolean processComponent(javax.faces.component.UIComponent uiComponent)
Based on basic rules the method checks if the current component should be processed.

Parameters:
uiComponent - The UIComponent which is processed.
Returns:
true if the given component should be processed by the current interceptor, false otherwise

getELHelper

protected ELHelper getELHelper()
Returns the ELHelper to be used in the process of the validation. It is cached for performance reasons.

Returns:
The ELHelper.

recordProcessedInformation

protected boolean recordProcessedInformation()
Signals if the converted value should be stored e.g. for the cross-validation process.

Returns:
true if the converted value should be recorded, false otherwise

getModuleKey

protected Class getModuleKey()
Identification of the validation module. A key is just needed if other implementations should be restricted to 1-n special validation modules.

Returns:
Identification of the validation module.

getPropertiesForComponentMetaDataExtractor

protected Map<String,Object> getPropertiesForComponentMetaDataExtractor(javax.faces.component.UIComponent uiComponent)
Create the properties which can be used by a MetaDataExtractor. By default it adds a key which identifies the current validation-module and the current component (to avoid changes of the api for quite special use-cases).

Parameters:
uiComponent - The UIComponent which is processed.
Returns:
properties used by the selection of the MetaDataExtractor

getInterceptorProperties

protected Map<String,Object> getInterceptorProperties(javax.faces.component.UIComponent uiComponent)
Create the properties which can be used by a MetaDataExtractor. Returns the properties which will be made available to interceptors. By default the moduleKey and the UIComponent itself is added.

Parameters:
uiComponent - The UIComponent which is processed.
Returns:
properties for the interceptors.


Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.