You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2009/04/12 19:42:18 UTC
svn commit: r764306 - in
/myfaces/extensions/validator/branches/beanval_integration/trunk:
core/src/main/java/org/apache/myfaces/extensions/validator/core/property/
validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validato...
Author: gpetracek
Date: Sun Apr 12 17:42:18 2009
New Revision: 764306
URL: http://svn.apache.org/viewvc?rev=764306&view=rev
Log:
minor refactorings and partial sync with trunk mechanisms
Modified:
myfaces/extensions/validator/branches/beanval_integration/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/property/DefaultPropertyInformation.java
myfaces/extensions/validator/branches/beanval_integration/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/property/PropertyInformation.java
myfaces/extensions/validator/branches/beanval_integration/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java
Modified: myfaces/extensions/validator/branches/beanval_integration/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/property/DefaultPropertyInformation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/beanval_integration/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/property/DefaultPropertyInformation.java?rev=764306&r1=764305&r2=764306&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/beanval_integration/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/property/DefaultPropertyInformation.java (original)
+++ myfaces/extensions/validator/branches/beanval_integration/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/property/DefaultPropertyInformation.java Sun Apr 12 17:42:18 2009
@@ -21,6 +21,8 @@
import org.apache.myfaces.extensions.validator.internal.UsageCategory;
import org.apache.myfaces.extensions.validator.internal.UsageInformation;
import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import java.util.HashMap;
import java.util.List;
@@ -34,6 +36,8 @@
@UsageInformation(UsageCategory.INTERNAL)
public class DefaultPropertyInformation implements PropertyInformation
{
+ protected final Log logger = LogFactory.getLog(getClass());
+
private Map<String, Object> informationMap = new HashMap<String, Object>();
private List<MetaDataEntry> metaDataList = new ArrayList<MetaDataEntry>();
@@ -54,6 +58,11 @@
public void setInformation(String key, Object value)
{
+ if(this.logger.isTraceEnabled())
+ {
+ this.logger.trace("new information added key: " + key + " value: " + value);
+ }
+
informationMap.put(key, value);
}
@@ -67,4 +76,14 @@
metaDataEntry.setProperties(this.informationMap);
this.metaDataList.add(metaDataEntry);
}
+
+ public void resetMetaDataEntries()
+ {
+ if(this.logger.isTraceEnabled())
+ {
+ this.logger.trace("resetting meta-data entries");
+ }
+
+ this.metaDataList.clear();
+ }
}
Modified: myfaces/extensions/validator/branches/beanval_integration/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/property/PropertyInformation.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/beanval_integration/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/property/PropertyInformation.java?rev=764306&r1=764305&r2=764306&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/beanval_integration/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/property/PropertyInformation.java (original)
+++ myfaces/extensions/validator/branches/beanval_integration/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/property/PropertyInformation.java Sun Apr 12 17:42:18 2009
@@ -36,4 +36,5 @@
MetaDataEntry[] getMetaDataEntries();
void addMetaDataEntry(MetaDataEntry metaDataEntry);
+ void resetMetaDataEntries();
}
Modified: myfaces/extensions/validator/branches/beanval_integration/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/beanval_integration/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java?rev=764306&r1=764305&r2=764306&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/beanval_integration/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java (original)
+++ myfaces/extensions/validator/branches/beanval_integration/trunk/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java Sun Apr 12 17:42:18 2009
@@ -197,7 +197,10 @@
try
{
- processValidation(facesContext, uiComponent, convertedObject);
+ if(processComponent(uiComponent))
+ {
+ processValidation(facesContext, uiComponent, convertedObject);
+ }
}
catch (ValidatorException e)
{
@@ -205,14 +208,14 @@
}
}
+ private boolean processComponent(UIComponent uiComponent)
+ {
+ return uiComponent instanceof EditableValueHolder;
+ }
+
@ToDo(value = Priority.HIGH, description = "use ExtValUtils#createFacesMessage")
protected void processValidation(FacesContext facesContext, UIComponent uiComponent, Object convertedObject)
{
- if (!(uiComponent instanceof EditableValueHolder))
- {
- return;
- }
-
if (logger.isTraceEnabled())
{
logger.trace("jsr303 start validation");
@@ -231,60 +234,7 @@
//extract group validation annotations
addMetaDataToContext(propertyInformation, uiComponent);
- Class baseBeanClass = (propertyInformation.getInformation(
- PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class)).getBaseObject().getClass();
-
- String propertyName = (propertyInformation.getInformation(
- PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class)).getProperty();
-
- ExtValBeanValidationContext beanValidationContext = ExtValBeanValidationContext.getCurrentInstance();
-
- Class[] groups = beanValidationContext.getGroups(
- facesContext.getViewRoot().getViewId(), uiComponent.getClientId(facesContext));
-
- if(groups == null)
- {
- return;
- }
-
- Set<ConstraintViolation> violations = this.validationFactory.usingContext()
- .messageInterpolator(ExtValBeanValidationContext.getCurrentInstance().getMessageInterpolator())
- .getValidator()
- .validateValue(baseBeanClass, propertyName, convertedObject, groups);
-
- if (violations != null && violations.size() > 0)
- {
- //TODO jsf 2.0 supports multiple messages -> use all messages
- ConstraintViolation violation = (ConstraintViolation) violations.toArray()[0];
-
- String violationMessage = violation.getMessage();
-
- String labeledMessage = "{0}: " + violationMessage;
- ValidatorException validatorException = new ValidatorException(
- new FacesMessage(FacesMessage.SEVERITY_ERROR, labeledMessage, labeledMessage));
-
- ExtValUtils.executeAfterThrowingInterceptors(
- uiComponent,
- null,
- convertedObject,
- validatorException,
- null);
-
- //TODO check & remove
- propertyInformation.setInformation(
- BeanValidationPropertyInformationKeys.CONSTRAINT_VIOLATIONS, violations);
-
- if (labeledMessage.equals(validatorException.getFacesMessage().getSummary()) ||
- labeledMessage.equals(validatorException.getFacesMessage().getDetail()))
- {
- throw new ValidatorException(
- new FacesMessage(FacesMessage.SEVERITY_ERROR, violationMessage, violationMessage));
- }
- else
- {
- throw validatorException;
- }
- }
+ processFieldValidation(facesContext, uiComponent, convertedObject, propertyInformation);
if (logger.isTraceEnabled())
{
@@ -292,7 +242,7 @@
}
}
- private void addMetaDataToContext(PropertyInformation propertyInformation, UIComponent component)
+ protected void addMetaDataToContext(PropertyInformation propertyInformation, UIComponent component)
{
PropertyDetails propertyDetails = propertyInformation
.getInformation(PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
@@ -345,6 +295,22 @@
String currentViewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
String clientId = component.getClientId(FacesContext.getCurrentInstance());
+
+ processFoundGroups(extValBeanValidationContext, currentViewId, clientId,
+ foundGroupsForPropertyValidation);
+
+ processRestrictedGroups(extValBeanValidationContext, currentViewId, clientId,
+ restrictedGroupsForPropertyValidation);
+
+ initModelValidation(extValBeanValidationContext, currentViewId, component, propertyDetails,
+ modelValidationEntryList, restrictedGroupsForModelValidation);
+ }
+
+ protected void processFoundGroups(ExtValBeanValidationContext extValBeanValidationContext,
+ String currentViewId,
+ String clientId,
+ List<Class> foundGroupsForPropertyValidation)
+ {
/*
* add found groups to context
*/
@@ -352,7 +318,13 @@
{
extValBeanValidationContext.addGroup(currentGroupClass, currentViewId, clientId);
}
+ }
+ protected void processRestrictedGroups(ExtValBeanValidationContext extValBeanValidationContext,
+ String currentViewId,
+ String clientId,
+ List<Class> restrictedGroupsForPropertyValidation)
+ {
/*
* add restricted groups
*/
@@ -360,7 +332,15 @@
{
extValBeanValidationContext.restrictGroup(currentGroupClass, currentViewId, clientId);
}
+ }
+ protected void initModelValidation(ExtValBeanValidationContext extValBeanValidationContext,
+ String currentViewId,
+ UIComponent component,
+ PropertyDetails propertyDetails,
+ List<ModelValidationEntry> modelValidationEntryList,
+ List<Class> restrictedGroupsForModelValidation)
+ {
/*
* add model validation entry list
*/
@@ -385,6 +365,67 @@
}
}
+ protected void processFieldValidation(FacesContext facesContext,
+ UIComponent uiComponent,
+ Object convertedObject,
+ PropertyInformation propertyInformation)
+ {
+ Class baseBeanClass = (propertyInformation.getInformation(
+ PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class)).getBaseObject().getClass();
+
+ String propertyName = (propertyInformation.getInformation(
+ PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class)).getProperty();
+
+ ExtValBeanValidationContext beanValidationContext = ExtValBeanValidationContext.getCurrentInstance();
+
+ Class[] groups = beanValidationContext.getGroups(
+ facesContext.getViewRoot().getViewId(), uiComponent.getClientId(facesContext));
+
+ if(groups == null)
+ {
+ return;
+ }
+
+ Set<ConstraintViolation> violations = this.validationFactory.usingContext()
+ .messageInterpolator(ExtValBeanValidationContext.getCurrentInstance().getMessageInterpolator())
+ .getValidator()
+ .validateValue(baseBeanClass, propertyName, convertedObject, groups);
+
+ if (violations != null && violations.size() > 0)
+ {
+ //TODO jsf 2.0 supports multiple messages -> use all messages
+ ConstraintViolation violation = (ConstraintViolation) violations.toArray()[0];
+
+ String violationMessage = violation.getMessage();
+
+ String labeledMessage = "{0}: " + violationMessage;
+ ValidatorException validatorException = new ValidatorException(
+ new FacesMessage(FacesMessage.SEVERITY_ERROR, labeledMessage, labeledMessage));
+
+ ExtValUtils.executeAfterThrowingInterceptors(
+ uiComponent,
+ null,
+ convertedObject,
+ validatorException,
+ null);
+
+ //TODO check & remove
+ propertyInformation.setInformation(
+ BeanValidationPropertyInformationKeys.CONSTRAINT_VIOLATIONS, violations);
+
+ if (labeledMessage.equals(validatorException.getFacesMessage().getSummary()) ||
+ labeledMessage.equals(validatorException.getFacesMessage().getDetail()))
+ {
+ throw new ValidatorException(
+ new FacesMessage(FacesMessage.SEVERITY_ERROR, violationMessage, violationMessage));
+ }
+ else
+ {
+ throw validatorException;
+ }
+ }
+ }
+
private void processClass(Object objectToInspect,
List<Class> foundGroupsForPropertyValidation,
List<Class> restrictedGroupsForPropertyValidation,