org.apache.myfaces.extensions.validator.core.validation.strategy
Class AbstractAnnotationValidationStrategy<A extends Annotation>

java.lang.Object
  extended by org.apache.myfaces.extensions.validator.core.validation.strategy.AbstractValidationStrategy
      extended by org.apache.myfaces.extensions.validator.core.validation.strategy.AbstractAnnotationValidationStrategy<A>
All Implemented Interfaces:
ValidationStrategy
Direct Known Subclasses:
AbstractCrossValidationStrategy, JpaValidationStrategy, PatternStrategy, RequiredStrategy

public abstract class AbstractAnnotationValidationStrategy<A extends Annotation>
extends AbstractValidationStrategy

This class provides an easier handling of violation messages. This abstract class is a good candidate as super-class for custom validation strategies.

Since:
1.x.1
Author:
Gerhard Petracek

Field Summary
protected static String DETAIL_MESSAGE_KEY_POSTFIX
           
 
Fields inherited from class org.apache.myfaces.extensions.validator.core.validation.strategy.AbstractValidationStrategy
logger
 
Constructor Summary
AbstractAnnotationValidationStrategy()
           
 
Method Summary
protected  String getErrorMessageDetail(A annotation)
          Returns the error message (the detailed message) provided by the given constraint.
protected  String getErrorMessageSummary(A annotation)
          Returns the error message (the summary) provided by the given constraint.
protected  String getLabel(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent uiComponent, MetaDataEntry metaDataEntry)
          Returns the label of the uiComponent field that could be used in the error messages.
protected  javax.faces.application.FacesMessage getValidationErrorFacesMessage(A annotation)
          Creates the FacesMessage that will be used to inform the user of a validation error.
protected abstract  String getValidationErrorMsgKey(A annotation)
          Returns the key for the message that needs to be resolved for the violation-message.
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  String resolveMessage(String key)
          Uses the given message key to resolve the actual message in the correct language.
 void setMessageResolver(MessageResolver messageResolver)
          Injection point for a MessageResolver that needs to be used by this ValidationStrategy.
 
Methods inherited from class org.apache.myfaces.extensions.validator.core.validation.strategy.AbstractValidationStrategy
initValidation, processValidation, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DETAIL_MESSAGE_KEY_POSTFIX

protected static final String DETAIL_MESSAGE_KEY_POSTFIX
See Also:
Constant Field Values
Constructor Detail

AbstractAnnotationValidationStrategy

public AbstractAnnotationValidationStrategy()
Method Detail

resolveMessage

protected String resolveMessage(String key)
Uses the given message key to resolve the actual message in the correct language. The current UIViewRoot provides the target locale. When a MessageResolver is available, it is used to resolve the message. Otherwise the default rules are taken to define the MessageResolver. ExtValUtils.getMessageResolverForValidationStrategy( org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy)

Parameters:
key - key of the error message that needs to be resolved.
Returns:
Resolved message.

getErrorMessageSummary

protected String getErrorMessageSummary(A annotation)
Returns the error message (the summary) provided by the given constraint. The message is determined by using the getValidationErrorMsgKey(A) method for obtaining the message-/key which then is resolved by the method resolveMessage.

Parameters:
annotation - The annotation associated with the ValidationStrategy.
Returns:
The error message used in the summary part of the FacesMessage.

getErrorMessageDetail

protected String getErrorMessageDetail(A annotation)
Returns the error message (the detailed message) provided by the given constraint. The message is determined by using the getValidationErrorMsgKey(A) method for obtaining the message-/key which then is resolved by the method resolveMessage. When the key isn't found, the resulting exception is just logged but not propagated. So the detail message isn't required and null is returned instead.

Parameters:
annotation - The annotation associated with the ValidationStrategy.
Returns:
The error message used in the detail part of the FacesMessage or null.

getValidationErrorFacesMessage

protected javax.faces.application.FacesMessage getValidationErrorFacesMessage(A annotation)
Creates the FacesMessage that will be used to inform the user of a validation error. This method can be called by subclasses in the processValidation method when a ValidatorException is thrown.

Parameters:
annotation - The annotation associated with the ValidationStrategy.
Returns:
FacesMessage for informing user of the problem.

getValidationErrorMsgKey

protected abstract String getValidationErrorMsgKey(A annotation)
Returns the key for the message that needs to be resolved for the violation-message.

Parameters:
annotation - The annotation associated with the ValidationStrategy.
Returns:
The key of the error message.

setMessageResolver

public void setMessageResolver(MessageResolver messageResolver)
Injection point for a MessageResolver that needs to be used by this ValidationStrategy.

Parameters:
messageResolver - messageResolver that needs to be used by this validationStrategy.

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. Adds the label of the component to the MetaDataEntry.

Overrides:
processAfterValidatorException in class AbstractValidationStrategy
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)

getLabel

protected String getLabel(javax.faces.context.FacesContext facesContext,
                          javax.faces.component.UIComponent uiComponent,
                          MetaDataEntry metaDataEntry)
Returns the label of the uiComponent field that could be used in the error messages. By default it returns null.

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.
Returns:
The label-text of the UIComponent which can be used in the violation msg.


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