You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/02/13 03:48:03 UTC
svn commit: r909699 - in
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets:
FaceletViewDeclarationLanguage.java tag/TagAttributeImpl.java
tag/TagValueExpressionMethodExpression.java
Author: lu4242
Date: Sat Feb 13 02:48:02 2010
New Revision: 909699
URL: http://svn.apache.org/viewvc?rev=909699&view=rev
Log:
MYFACES-2553 Handle MethodExpressions on <composite:attribute> correctly
Added:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagValueExpressionMethodExpression.java
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagAttributeImpl.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java?rev=909699&r1=909698&r2=909699&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java Sat Feb 13 02:48:02 2010
@@ -870,6 +870,10 @@
_getParameters(methodSignature));
topLevelComponent.getAttributes().put(attributeName, methodExpression);
}
+
+ // We need to remove the previous ValueExpression, to prevent some possible
+ // confusion when the same value is retrieved from the attribute map.
+ topLevelComponent.setValueExpression(attributeName, null);
}
}
}
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=909699&r1=909698&r2=909699&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 Sat Feb 13 02:48:02 2010
@@ -153,14 +153,49 @@
{
try
{
- ExpressionFactory f = ctx.getExpressionFactory();
- return new TagMethodExpression(this, f.createMethodExpression(ctx, this.value, type, paramTypes));
+ // From this point we can suppose this attribute contains a ELExpression
+ // Now we have to check if the expression points to a composite component attribute map
+ // and if so deal with it as an indirection.
+ if (isCompositeComponentAttributeMapExpression())
+ {
+ // The MethodExpression is on parent composite component attribute map.
+ // create a pointer that are referred to the real one that is created in other side
+ // (see VDL.retargetMethodExpressions for details)
+ ValueExpression valueExpr = this.getValueExpression(ctx, MethodExpression.class);
+ return new TagValueExpressionMethodExpression(this, valueExpr);
+ }
+ else
+ {
+ ExpressionFactory f = ctx.getExpressionFactory();
+ return new TagMethodExpression(this, f.createMethodExpression(ctx, this.value, type, paramTypes));
+ }
}
catch (Exception e)
{
throw new TagAttributeException(this, e);
}
}
+
+ private boolean isCompositeComponentAttributeMapExpression()
+ {
+ // Check if the ELExpression inside this.value has as target the composite component attribute map
+ // and if so, return true, otherwise return false.
+ int i = this.value.indexOf("cc.");
+ if (i >= 0)
+ {
+ i = this.value.indexOf("attrs.",i+3);
+ if (i >= 0)
+ {
+ // If the last target is a value inside the composite attribute map
+ // we are in case.
+ if (this.value.indexOf('.',i+6) < 0)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
/**
* The resolved Namespace for this attribute
Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagValueExpressionMethodExpression.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagValueExpressionMethodExpression.java?rev=909699&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagValueExpressionMethodExpression.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/TagValueExpressionMethodExpression.java Sat Feb 13 02:48:02 2010
@@ -0,0 +1,172 @@
+/*
+ * 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.tag;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import javax.el.ELContext;
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.el.MethodInfo;
+import javax.el.MethodNotFoundException;
+import javax.el.PropertyNotFoundException;
+import javax.el.ValueExpression;
+import javax.faces.view.facelets.TagAttribute;
+
+/**
+ * This class is used to retrieve a MethodExpression indirectly, "jumping" between composite component
+ * attribute maps.
+ *
+ * @author Leonardo Uribe
+ * @version $Id: TagValueExpression.java,v 1.7 2008/07/13 19:01:42 rlubke Exp $
+ */
+public final class TagValueExpressionMethodExpression extends MethodExpression implements Externalizable
+{
+
+ private static final long serialVersionUID = 1L;
+
+ private ValueExpression orig;
+
+ private String attr;
+
+ public TagValueExpressionMethodExpression()
+ {
+ super();
+ }
+
+ public TagValueExpressionMethodExpression(TagAttribute attr, ValueExpression orig)
+ {
+ this.attr = attr.toString();
+ this.orig = orig;
+ }
+
+ private Object getValue(ELContext context)
+ {
+ try
+ {
+ return this.orig.getValue(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());
+ }
+ }
+
+ public boolean equals(Object obj)
+ {
+ return this.orig.equals(obj);
+ }
+
+ public String getExpressionString()
+ {
+ return this.orig.getExpressionString();
+ }
+
+ public int hashCode()
+ {
+ return this.orig.hashCode();
+ }
+
+ public boolean isLiteralText()
+ {
+ return this.orig.isLiteralText();
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ this.orig = (ValueExpression) in.readObject();
+ this.attr = in.readUTF();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeObject(this.orig);
+ out.writeUTF(this.attr);
+ }
+
+ public String toString()
+ {
+ return this.attr + ": " + this.orig;
+ }
+
+ @Override
+ public MethodInfo getMethodInfo(ELContext context)
+ {
+ try
+ {
+ final MethodExpression expr = (MethodExpression)this.getValue(context);
+ if (expr != null)
+ {
+ return expr.getMethodInfo(context);
+ }
+ else
+ {
+ throw new PropertyNotFoundException(this.attr);
+ }
+ }
+ catch (PropertyNotFoundException pnfe)
+ {
+ throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
+ }
+ catch (MethodNotFoundException mnfe)
+ {
+ throw new MethodNotFoundException(this.attr + ": " + mnfe.getMessage(), mnfe.getCause());
+ }
+ catch (ELException e)
+ {
+ throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
+ }
+ }
+
+ @Override
+ public Object invoke(ELContext context, Object[] params)
+ {
+ try
+ {
+ final MethodExpression expr = (MethodExpression)this.getValue(context);
+ if (expr != null)
+ {
+ return expr.invoke(context, params);
+ }
+ else
+ {
+ throw new PropertyNotFoundException(this.attr);
+ }
+ }
+ catch (PropertyNotFoundException pnfe)
+ {
+ throw new PropertyNotFoundException(this.attr + ": " + pnfe.getMessage(), pnfe.getCause());
+ }
+ catch (MethodNotFoundException mnfe)
+ {
+ throw new MethodNotFoundException(this.attr + ": " + mnfe.getMessage(), mnfe.getCause());
+ }
+ catch (ELException e)
+ {
+ throw new ELException(this.attr + ": " + e.getMessage(), e.getCause());
+ }
+ }
+}
\ No newline at end of file