org.apache.myfaces.extensions.validator.core.validation.strategy
Class AbstractValidationStrategy

java.lang.Object
  extended by org.apache.myfaces.extensions.validator.core.validation.strategy.AbstractValidationStrategy
All Implemented Interfaces:
ValidationStrategy
Direct Known Subclasses:
AbstractAnnotationValidationStrategy, DoubleRangeStrategy, JoinValidationStrategy, LengthStrategy, LongRangeStrategy, ValidatorStrategy

public abstract class AbstractValidationStrategy
extends Object
implements ValidationStrategy

Provides the ability to use ValidatorException (as expected by the user) instead of the internally needed ConverterException. Furthermore, this base implementation introduces a hook for the initialization of validators and the interception of ValidatorExceptions.

Since:
1.x.1

Field Summary
protected  Logger logger
           
 
Constructor Summary
protected AbstractValidationStrategy()
           
 
Method Summary
protected  void initValidation(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, MetaDataEntry metaDataEntry, Object convertedObject)
          Allows some initialization before the actual validation is performed.
protected  boolean processAfterValidatorException(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, MetaDataEntry metaDataEntry, Object convertedObject, javax.faces.validator.ValidatorException validatorException)
          Executes the registered ValidationExceptionInterceptor to process the validation exception.
protected abstract  void processValidation(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, MetaDataEntry metaDataEntry, Object convertedObject)
          Validates the given value based on the given meta-data entry.
 void validate(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, MetaDataEntry metaDataEntry, Object convertedObject)
          Validates the convertedObject against the given MetaDataEntry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Logger logger
Constructor Detail

AbstractValidationStrategy

protected AbstractValidationStrategy()
Method Detail

validate

public void validate(javax.faces.context.FacesContext facesContext,
                     javax.faces.component.UIComponent uiComponent,
                     MetaDataEntry metaDataEntry,
                     Object convertedObject)
Validates the convertedObject against the given MetaDataEntry. Before actually executing the validation (processValidation(javax.faces.context.FacesContext, javax.faces.component.UIComponent, org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry, java.lang.Object)) any initialization can be performed by overriding initValidation(javax.faces.context.FacesContext, javax.faces.component.UIComponent, org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry, java.lang.Object). If a Validation exception occurs, the method processAfterValidatorException(javax.faces.context.FacesContext, javax.faces.component.UIComponent, org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry, java.lang.Object, javax.faces.validator.ValidatorException) executes the registered ValidationExceptionInterceptor's.

Specified by:
validate in interface ValidationStrategy
Parameters:
facesContext - The JSF Context
uiComponent - The JSF component that contained the value entered by the user.
metaDataEntry - The data holder which stores the meta-data and some information where the meta-data was around.
convertedObject - Converted object of the user entered value.

initValidation

protected void initValidation(javax.faces.context.FacesContext facesContext,
                              javax.faces.component.UIComponent uiComponent,
                              MetaDataEntry metaDataEntry,
                              Object convertedObject)
Allows some initialization before the actual validation is performed. This initialization is executed before each validation and not only once when th class is constructed.

Parameters:
facesContext - The JSF Context
uiComponent - The JSF component that contained the value entered by the user.
metaDataEntry - The data holder which stores the meta-data and some information where the meta-data was around.
convertedObject - Converted object of the user entered value.

processAfterValidatorException

protected boolean processAfterValidatorException(javax.faces.context.FacesContext facesContext,
                                                 javax.faces.component.UIComponent uiComponent,
                                                 MetaDataEntry metaDataEntry,
                                                 Object convertedObject,
                                                 javax.faces.validator.ValidatorException validatorException)
Executes the registered ValidationExceptionInterceptor to process the validation exception.

Parameters:
facesContext - The JSF Context
uiComponent - The JSF component that contained the value entered by the user.
metaDataEntry - The data holder which stores the meta-data and some information where the meta-data was around.
convertedObject - Converted object of the user entered value.
validatorException - The validation exception that occurred.
Returns:
should return true when you like to have the ValidatorException thrown by the ExtValUtils#tryToThrowValidatorExceptionForComponent method. ExtValUtils.tryToThrowValidatorExceptionForComponent(javax.faces.component.UIComponent, javax.faces.application.FacesMessage, java.lang.Throwable)

processValidation

protected abstract void processValidation(javax.faces.context.FacesContext facesContext,
                                          javax.faces.component.UIComponent uiComponent,
                                          MetaDataEntry metaDataEntry,
                                          Object convertedObject)
                                   throws javax.faces.validator.ValidatorException
Validates the given value based on the given meta-data entry. The method throws a ValidatorException if a violation is detected

Parameters:
facesContext - The JSF Context
uiComponent - The JSF component that contained the value entered by the user.
metaDataEntry - The data holder which stores the meta-data and some information where the meta-data was around.
convertedObject - Converted object of the user entered value.
Throws:
javax.faces.validator.ValidatorException - When violation of the validation rules occurs.


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