You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by st...@apache.org on 2010/07/20 18:50:23 UTC

svn commit: r965901 - in /myfaces/core/trunk/api/src/main/java/javax/faces/validator: BeanValidator.java _BeanValidatorUELUtils.java

Author: struberg
Date: Tue Jul 20 16:50:23 2010
New Revision: 965901

URL: http://svn.apache.org/viewvc?rev=965901&view=rev
Log:
MYFACES-2830 skip validation at all if the valueExpression is null 

We cannot validate a component which has no value. 
Rolled back my previous change because it's not needed anymore.

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java
    myfaces/core/trunk/api/src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java?rev=965901&r1=965900&r2=965901&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/validator/BeanValidator.java Tue Jul 20 16:50:23 2010
@@ -28,6 +28,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Set;
+import java.util.logging.Logger;
 
 import javax.el.ELContext;
 import javax.el.ELResolver;
@@ -75,7 +76,7 @@ import org.apache.myfaces.buildtools.mav
 public class BeanValidator implements Validator, PartialStateHolder
 {
 
-//    private static final Logger log = Logger.getLogger(BeanValidator.class.getName());
+    private static final Logger log = Logger.getLogger(BeanValidator.class.getName());
 
     /**
      * Converter ID, as defined by the JSF 2.0 specification.
@@ -130,6 +131,12 @@ public class BeanValidator implements Va
         if (context == null) throw new NullPointerException("context");
         if (component == null) throw new NullPointerException("component");
 
+        if (component.getValueExpression("value") == null)
+        {
+            log.warning("cannot validate component with empty value" + component.getId());
+            return;
+        }
+
         // Obtain a reference to the to-be-validated object and the property name.
         final _ValueReferenceWrapper reference = getValueReference(component, context);
         if (reference == null)
@@ -220,12 +227,7 @@ public class BeanValidator implements Va
             
             // we can't access ValueExpression.getValueReference() directly here, because
             // Class loading would fail in applications with el-api versions prior to 2.2
-            _ValueReferenceWrapper valueReference 
-                    = _BeanValidatorUELUtils.getUELValueReferenceWrapper(valueExpression, elCtx);
-            if (valueReference != null)
-            {
-                return valueReference;
-            }
+            return  _BeanValidatorUELUtils.getUELValueReferenceWrapper(valueExpression, elCtx);
         }
         
         // get base object and property name the "old-fashioned" way
@@ -556,11 +558,6 @@ final class _ValueReferenceResolver exte
      */
     public static _ValueReferenceWrapper resolve(ValueExpression valueExpression, final ELContext elCtx)
     {
-        if(valueExpression == null)
-        {
-            return null;
-        }
-        
         final _ValueReferenceResolver resolver = new _ValueReferenceResolver(elCtx.getELResolver());
         final ELContext elCtxDecorator = new _ELContextDecorator(elCtx, resolver);
         
@@ -599,9 +596,6 @@ final class _ValueReferenceResolver exte
     public final boolean isReadOnly(final ELContext ctx, final Object base, final Object property){return resolver.isReadOnly(ctx, base, property);}
     public final Iterator<FeatureDescriptor> getFeatureDescriptors(final ELContext ctx, final Object base){return resolver.getFeatureDescriptors(ctx, base);}
     public final Class<?> getCommonPropertyType(final ELContext ctx, final Object base){return resolver.getCommonPropertyType(ctx, base);}
-    public final Object invoke(ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params) {
-        return resolver.invoke(context, base, method, paramTypes, params);
-    }
 }
 
 /**

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java?rev=965901&r1=965900&r2=965901&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/validator/_BeanValidatorUELUtils.java Tue Jul 20 16:50:23 2010
@@ -38,17 +38,12 @@ final class _BeanValidatorUELUtils
     /**
      * Get the ValueReference from the ValueExpression.
      *
-     * @param component The component.
-     * @param context The FacesContext.
+     * @param valueExpression
+     * @param elCtx
      * @return A ValueReferenceWrapper with the necessary information about the ValueReference.
      */
     public static _ValueReferenceWrapper getUELValueReferenceWrapper(ValueExpression valueExpression, final ELContext elCtx)
     {
-        if(valueExpression == null)
-        {
-            return null;
-        }
-                
         ValueReference valueReference = valueExpression.getValueReference(elCtx);
         
         while (valueReference != null 
@@ -63,11 +58,12 @@ final class _BeanValidatorUELUtils
             valueReference = valueExpression.getValueReference(elCtx);
         }
         
-        if (valueReference == null)
+        if (valueReference != null)
         {
-            return null;
+            return new _ValueReferenceWrapper(valueReference.getBase(), valueReference.getProperty());
         }
-        return new _ValueReferenceWrapper(valueReference.getBase(), valueReference.getProperty());
+        
+        return null;
     }
 
 }