myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r833635 - in /myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval: interceptor/ startup/ util/ validation/
Date Sat, 07 Nov 2009 06:15:29 GMT
Author: gpetracek
Date: Sat Nov  7 06:15:28 2009
New Revision: 833635

URL: http://svn.apache.org/viewvc?rev=833635&view=rev
Log:
refactored exception handling (bv integration)

Added:
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/interceptor/BeanValidationExceptionInterceptor.java
Modified:
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java

Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/interceptor/BeanValidationExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/interceptor/BeanValidationExceptionInterceptor.java?rev=833635&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/interceptor/BeanValidationExceptionInterceptor.java
(added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/interceptor/BeanValidationExceptionInterceptor.java
Sat Nov  7 06:15:28 2009
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.beanval.interceptor;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.core.interceptor.ValidationExceptionInterceptor;
+import org.apache.myfaces.extensions.validator.core.InvocationOrder;
+import org.apache.myfaces.extensions.validator.core.ExtValContext;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.EditableValueHolder;
+import javax.faces.validator.ValidatorException;
+import javax.faces.context.FacesContext;
+
+/**
+ * extracts and adds the extval bv meta-data (e.g. validation groups) to the ExtValBeanValidationContext
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@InvocationOrder(200)
+@UsageInformation(UsageCategory.INTERNAL)
+public class BeanValidationExceptionInterceptor implements ValidationExceptionInterceptor
+{
+
+    public boolean afterThrowing(UIComponent uiComponent,
+                                 MetaDataEntry metaDataEntry,
+                                 Object convertedObject,
+                                 ValidatorException validatorException,
+                                 ValidationStrategy validatorExceptionSource)
+    {
+        if(uiComponent instanceof EditableValueHolder && isBlockingException(uiComponent,
validatorException))
+        {
+            //bv integration doesn't throw exceptions to support multiple messages ->
set component state
+            ((EditableValueHolder)uiComponent).setValid(false);
+        }
+        return true;
+    }
+
+    private boolean isBlockingException(UIComponent uiComponent, ValidatorException validatorException)
+    {
+        return ExtValContext.getContext().getViolationSeverityInterpreter().severityCausesValidatorException(
+                FacesContext.getCurrentInstance(),
+                uiComponent,
+                validatorException.getFacesMessage().getSeverity());
+    }
+}

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java?rev=833635&r1=833634&r2=833635&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/startup/BeanValidationStartupListener.java
Sat Nov  7 06:15:28 2009
@@ -21,6 +21,7 @@
 import org.apache.myfaces.extensions.validator.beanval.BeanValidationInterceptor;
 import org.apache.myfaces.extensions.validator.beanval.HtmlCoreComponentsComponentInitializer;
 import org.apache.myfaces.extensions.validator.beanval.interceptor.ExtValBeanValidationMetaDataExtractionInterceptor;
+import org.apache.myfaces.extensions.validator.beanval.interceptor.BeanValidationExceptionInterceptor;
 import org.apache.myfaces.extensions.validator.beanval.validation.ModelValidationPhaseListener;
 import org.apache.myfaces.extensions.validator.beanval.metadata.transformer.mapper.SizeNameMapper;
 import org.apache.myfaces.extensions.validator.beanval.metadata.transformer.mapper.NotNullNameMapper;
@@ -62,6 +63,7 @@
         registerComponentInitializers();
         registerMetaDataExtractionInterceptors();
         registerPhaseListeners();
+        registerExceptionInterceptor();
     }
 
     protected void registerValidatorFactory()
@@ -131,4 +133,9 @@
     {
         JsfUtils.registerPhaseListener(new ModelValidationPhaseListener());
     }
+
+    protected void registerExceptionInterceptor()
+    {
+        ExtValContext.getContext().addValidationExceptionInterceptor(new BeanValidationExceptionInterceptor());
+    }
 }

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java?rev=833635&r1=833634&r2=833635&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
Sat Nov  7 06:15:28 2009
@@ -29,7 +29,6 @@
 
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
-import javax.faces.component.EditableValueHolder;
 import javax.faces.context.FacesContext;
 import javax.faces.validator.ValidatorException;
 import javax.validation.ConstraintViolation;
@@ -96,7 +95,7 @@
             bvmi.processFacesMessage(facesContext, uiComponent, facesMessageHolderList, facesMessage);
         }
 
-        processViolationMessages(facesMessageHolderList, uiComponent);
+        processViolationMessages(facesMessageHolderList);
     }
 
     public static FacesMessage createFacesMessageForConstraintViolation(UIComponent uiComponent,
@@ -130,8 +129,7 @@
         }
     }
 
-    public static void processViolationMessages(List<FacesMessageHolder> violationMessageHolderList,
-                                                UIComponent uiComponent)
+    public static void processViolationMessages(List<FacesMessageHolder> violationMessageHolderList)
     {
         if (violationMessageHolderList == null || violationMessageHolderList.isEmpty())
         {
@@ -143,21 +141,7 @@
         List<FacesMessageHolder> facesMessageListWithHighSeverity =
                 bvmi.getFacesMessageListWithHighSeverity(violationMessageHolderList);
 
-        tryToSetComponentInvalid(uiComponent, facesMessageListWithHighSeverity);
-
         bvmi.addMessages(facesMessageListWithHighSeverity);
         bvmi.addMessages(facesMessageListWithLowSeverity);
     }
-
-    private static void tryToSetComponentInvalid(
-            UIComponent uiComponent, List<FacesMessageHolder> facesMessageListWithHighSeverity)
-    {
-        if(!facesMessageListWithHighSeverity.isEmpty())
-        {
-            if(uiComponent instanceof EditableValueHolder)
-            {
-                ((EditableValueHolder)uiComponent).setValid(false);
-            }
-        }
-    }
 }

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java?rev=833635&r1=833634&r2=833635&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationPhaseListener.java
Sat Nov  7 06:15:28 2009
@@ -433,7 +433,7 @@
     {
         for (ModelValidationResult result : results.values())
         {
-            BeanValidationUtils.processViolationMessages(result.getFacesMessageHolderList(),
null);
+            BeanValidationUtils.processViolationMessages(result.getFacesMessageHolderList());
         }
     }
 



Mime
View raw message