myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jak...@apache.org
Subject svn commit: r928752 - in /myfaces/core/trunk: api/src/main/java/javax/faces/validator/ impl/src/main/java/org/apache/myfaces/view/facelets/el/ impl/src/main/java/org/apache/myfaces/view/facelets/tag/
Date Mon, 29 Mar 2010 12:28:21 GMT
Author: jakobk
Date: Mon Mar 29 12:28:20 2010
New Revision: 928752

URL: http://svn.apache.org/viewvc?rev=928752&view=rev
Log:
MYFACES-2621 BeanValidation does not work with Unified EL 2.2 (solution for ValueExpression
wrappers)

Added:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpressionUEL.java
  (with props)
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java
  (with props)
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
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpression.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpression.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.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=928752&r1=928751&r2=928752&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 Mon Mar
29 12:28:20 2010
@@ -207,8 +207,6 @@ public class BeanValidator implements Va
         {
             // unified el 2.2 is available --> we can use ValueExpression.getValueReference()
             
-            // TODO handle wrapped ValueExpressions
-            
             // 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 

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=928752&r1=928751&r2=928752&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
Mon Mar 29 12:28:20 2010
@@ -21,6 +21,7 @@ package javax.faces.validator;
 import javax.el.ELContext;
 import javax.el.ValueExpression;
 import javax.el.ValueReference;
+import javax.faces.el.CompositeComponentExpressionHolder;
 
 /**
  * Utility class that isolates UEL calls, to prevent ClassNotFoundException
@@ -41,9 +42,18 @@ final class _BeanValidatorUELUtils
      * @param context The FacesContext.
      * @return A ValueReferenceWrapper with the necessary information about the ValueReference.
      */
-    public static _ValueReferenceWrapper getUELValueReferenceWrapper(final ValueExpression
valueExpression, final ELContext elCtx)
+    public static _ValueReferenceWrapper getUELValueReferenceWrapper(ValueExpression valueExpression,
final ELContext elCtx)
     {
-        final ValueReference valueReference = valueExpression.getValueReference(elCtx);
+        ValueReference valueReference = valueExpression.getValueReference(elCtx);
+        
+        while (valueReference != null 
+                && valueReference.getBase() instanceof CompositeComponentExpressionHolder)
+        {
+            valueExpression = ((CompositeComponentExpressionHolder) valueReference.getBase())
+                                  .getExpression((String) valueReference.getProperty());
+            valueReference = valueExpression.getValueReference(elCtx);
+        }
+        
         if (valueReference == null)
         {
             return null;

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpression.java?rev=928752&r1=928751&r2=928752&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpression.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpression.java
Mon Mar 29 12:28:20 2010
@@ -43,8 +43,9 @@ public class LocationValueExpression ext
     
     private static final long serialVersionUID = -5636849184764526288L;
     
-    private Location location;
-    private ValueExpression delegate;
+    // location and delegate need to be available in LocationValueExpressionUEL
+    Location location;
+    ValueExpression delegate;
     
     public LocationValueExpression(Location location, ValueExpression delegate)
     {

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpressionUEL.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpressionUEL.java?rev=928752&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpressionUEL.java
(added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpressionUEL.java
Mon Mar 29 12:28:20 2010
@@ -0,0 +1,58 @@
+/*
+ * 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.view.facelets.el;
+
+import javax.el.ELContext;
+import javax.el.ValueExpression;
+import javax.el.ValueReference;
+import javax.faces.context.FacesContext;
+import javax.faces.view.Location;
+
+/**
+ * LocationValueExpression for el-api 2.2
+ * 
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class LocationValueExpressionUEL extends LocationValueExpression
+{
+
+    private static final long serialVersionUID = 1824869909994211424L;
+
+    public LocationValueExpressionUEL(Location location, ValueExpression delegate)
+    {
+        super(location, delegate);
+    }
+    
+    @Override
+    public ValueReference getValueReference(ELContext context)
+    {
+        FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
+        CompositeComponentELUtils.saveCompositeComponentForResolver(facesContext, location);
+        try
+        {
+            return delegate.getValueReference(context);
+        }
+        finally
+        {
+            CompositeComponentELUtils.removeCompositeComponentForResolver(facesContext);
+        }
+    }
+
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpressionUEL.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpressionUEL.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/LocationValueExpressionUEL.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpression.java?rev=928752&r1=928751&r2=928752&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpression.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpression.java
Mon Mar 29 12:28:20 2010
@@ -36,14 +36,14 @@ import javax.faces.view.facelets.TagAttr
  * @author Jacob Hookom
  * @version $Id: TagValueExpression.java,v 1.7 2008/07/13 19:01:42 rlubke Exp $
  */
-public final class TagValueExpression extends ValueExpression implements Externalizable
+public class TagValueExpression extends ValueExpression implements Externalizable
 {
 
     private static final long serialVersionUID = 1L;
 
-    private ValueExpression orig;
-
-    private String attr;
+    // orig and attr need to be available in TagValueExpressionUEL
+    ValueExpression orig; 
+    String attr; 
 
     public TagValueExpression()
     {
@@ -128,7 +128,7 @@ public final class TagValueExpression ex
             throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
         }
     }
-
+    
     public boolean equals(Object obj)
     {
         return this.orig.equals(obj);

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java?rev=928752&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java
(added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java
Mon Mar 29 12:28:20 2010
@@ -0,0 +1,64 @@
+/*
+ * 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.view.facelets.el;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.PropertyNotFoundException;
+import javax.el.ValueExpression;
+import javax.el.ValueReference;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ * TagValueExpression for el-api 2.2
+ * 
+ * @author Jakob Korherr (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class TagValueExpressionUEL extends TagValueExpression
+{
+
+    public TagValueExpressionUEL()
+    {
+        super();
+    }
+
+    public TagValueExpressionUEL(TagAttribute attr, ValueExpression orig)
+    {
+        super(attr, orig);
+    }
+    
+    @Override
+    public ValueReference getValueReference(ELContext context)
+    {
+        try
+        {
+            return this.orig.getValueReference(context);
+        }
+        catch (PropertyNotFoundException pnfe)
+        {
+            throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
+        }
+        catch (ELException e)
+        {
+            throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
+        }
+    }
+    
+}

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/el/TagValueExpressionUEL.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.java?rev=928752&r1=928751&r2=928752&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.java
Mon Mar 29 12:28:20 2010
@@ -27,12 +27,15 @@ import javax.faces.view.facelets.Facelet
 import javax.faces.view.facelets.TagAttribute;
 import javax.faces.view.facelets.TagAttributeException;
 
+import org.apache.myfaces.util.ExternalSpecifications;
 import org.apache.myfaces.view.facelets.el.CompositeComponentELUtils;
 import org.apache.myfaces.view.facelets.el.ELText;
 import org.apache.myfaces.view.facelets.el.LocationMethodExpression;
 import org.apache.myfaces.view.facelets.el.LocationValueExpression;
+import org.apache.myfaces.view.facelets.el.LocationValueExpressionUEL;
 import org.apache.myfaces.view.facelets.el.TagMethodExpression;
 import org.apache.myfaces.view.facelets.el.TagValueExpression;
+import org.apache.myfaces.view.facelets.el.TagValueExpressionUEL;
 import org.apache.myfaces.view.facelets.el.ValueExpressionMethodExpression;
 
 /**
@@ -350,10 +353,24 @@ public final class TagAttributeImpl exte
             // (see MYFACES-2561 for details)
             if (CompositeComponentELUtils.isCompositeComponentExpression(this.value))
             {
-                valueExpression = new LocationValueExpression(getLocation(), valueExpression);
+                if (ExternalSpecifications.isUnifiedELAvailable())
+                {
+                    valueExpression = new LocationValueExpressionUEL(getLocation(), valueExpression);
+                }
+                else
+                {
+                    valueExpression = new LocationValueExpression(getLocation(), valueExpression);
+                }
             }
             
-            return new TagValueExpression(this, valueExpression);
+            if (ExternalSpecifications.isUnifiedELAvailable())
+            {
+                return new TagValueExpressionUEL(this, valueExpression);
+            }
+            else
+            {
+                return new TagValueExpression(this, valueExpression);
+            }
         }
         catch (Exception e)
         {



Mime
View raw message