myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r909661 - in /myfaces/core/trunk/impl/src: main/java/org/apache/myfaces/view/facelets/ main/java/org/apache/myfaces/view/facelets/tag/composite/ test/java/org/apache/myfaces/view/facelets/tag/composite/ test/resources/org/apache/myfaces/vie...
Date Fri, 12 Feb 2010 23:38:34 GMT
Author: lu4242
Date: Fri Feb 12 23:38:34 2010
New Revision: 909661

URL: http://svn.apache.org/viewvc?rev=909661&view=rev
Log:
MYFACES-2553 Handle MethodExpressions on <composite:attribute> correctly (fix ViewDeclarationLanguage.retargetMethodExpressions
method)

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/composite/CompositeComponentResourceTagHandler.java
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentTestCase.java
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleAttributeMethodExpression.xhtml

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=909661&r1=909660&r2=909661&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
Fri Feb 12 23:38:34 2010
@@ -778,79 +778,98 @@
                         attributeNameValueExpression = (ValueExpression) propertyDescriptor.getValue("default");
                         if (attributeNameValueExpression == null)
                         {
-                            if (log.isLoggable(Level.SEVERE))
-                                log.severe("attributeValueExpression not found under the
key \""+attributeName+
-                                        "\". Looking for the next attribute");
+                            // It is only valid to log an error if the attribute is required
+                            ValueExpression ve = (ValueExpression) propertyDescriptor.getValue("required");
+                            if (ve != null)
+                            {
+                                // QUESTION: Almost positive that the value expression is
supposed to evaluate to a boolean, but originally
+                                // the code assumed it to be a string.  Can someone verify
what the right type is?
+                                // ANS: -= Leonardo Uribe =- Take a look at AttributeHandler.
The correct type is Boolean, so we can cast safe 
+                                Boolean required = (Boolean) ve.getValue (context.getELContext());
+                                
+                                if (required != null && required.booleanValue())
+                                {
+                                    if (log.isLoggable(Level.SEVERE))
+                                        log.severe("attributeValueExpression not found under
the key \""+attributeName+
+                                                "\". Looking for the next attribute");
+                                }
+                            }
                             continue;
                         }
                     }
                     
                     String attributeExpressionString = attributeNameValueExpression.getExpressionString();
                     MethodExpression methodExpression = null;
-                                        
-                    for (String target : targetsArray)
+                    
+                    if ("action".equals(attributeName) || "actionListener".equals(attributeName)
|| 
+                        "validator".equals(attributeName) || "valueChangeListener".equals(attributeName))
                     {
-                        UIComponent innerComponent = topLevelComponent.findComponent(target);
-                        
-                        if (innerComponent == null)
+                        for (String target : targetsArray)
                         {
-                            if (log.isLoggable(Level.SEVERE))
-                                log.severe("Inner component "+target+"not found when retargetMethodExpressions");
-                            continue;
-                        }
+                            UIComponent innerComponent = topLevelComponent.findComponent(target);
+                            
+                            if (innerComponent == null)
+                            {
+                                if (log.isLoggable(Level.SEVERE))
+                                    log.severe("Inner component "+target+"not found when
retargetMethodExpressions");
+                                continue;
+                            }
 
-                        if ("action".equals(attributeName))
-                        {
-                            // target is ActionSource2
-                            methodExpression = context.getApplication().getExpressionFactory().
+                            if ("action".equals(attributeName))
+                            {
+                                // target is ActionSource2
+                                methodExpression = context.getApplication().getExpressionFactory().
+                                    createMethodExpression(context.getELContext(),
+                                            attributeExpressionString, Object.class, new
Class[]{});
+                                
+                                ((ActionSource2)innerComponent).setActionExpression(methodExpression);
+                            }
+                            else if ("actionListener".equals(attributeName))
+                            {
+                               // target is ActionSource2
+                                methodExpression = context.getApplication().getExpressionFactory().
                                 createMethodExpression(context.getELContext(),
-                                        attributeExpressionString, Object.class, new Class[]{});
-                            
-                            ((ActionSource2)innerComponent).setActionExpression(methodExpression);
-                        }
-                        else if ("actionListener".equals(attributeName))
-                        {
-                           // target is ActionSource2
-                            methodExpression = context.getApplication().getExpressionFactory().
-                            createMethodExpression(context.getELContext(),
-                                    attributeExpressionString, Void.TYPE, new Class[]{ActionEvent.class});
-                            
-                            ((ActionSource)innerComponent).addActionListener(
-                                    new MethodExpressionActionListener(methodExpression));
-                        }
-                        else if ("validator".equals(attributeName))
-                        {
-                            // target is EditableValueHolder
-                            methodExpression = context.getApplication().getExpressionFactory().
-                            createMethodExpression(context.getELContext(),
-                                    attributeExpressionString, Void.TYPE, 
-                                    new Class[]{FacesContext.class, UIComponent.class, Object.class});
+                                        attributeExpressionString, Void.TYPE, new Class[]{ActionEvent.class});
+                                
+                                ((ActionSource)innerComponent).addActionListener(
+                                        new MethodExpressionActionListener(methodExpression));
+                            }
+                            else if ("validator".equals(attributeName))
+                            {
+                                // target is EditableValueHolder
+                                methodExpression = context.getApplication().getExpressionFactory().
+                                createMethodExpression(context.getELContext(),
+                                        attributeExpressionString, Void.TYPE, 
+                                        new Class[]{FacesContext.class, UIComponent.class,
Object.class});
 
-                            ((EditableValueHolder)innerComponent).addValidator(
-                                    new MethodExpressionValidator(methodExpression));
-                        }
-                        else if ("valueChangeListener".equals(attributeName))
-                        {
-                            // target is EditableValueHolder
-                            methodExpression = context.getApplication().getExpressionFactory().
-                            createMethodExpression(context.getELContext(),
-                                    attributeExpressionString, Void.TYPE, 
-                                    new Class[]{ValueChangeEvent.class});
+                                ((EditableValueHolder)innerComponent).addValidator(
+                                        new MethodExpressionValidator(methodExpression));
+                            }
+                            else if ("valueChangeListener".equals(attributeName))
+                            {
+                                // target is EditableValueHolder
+                                methodExpression = context.getApplication().getExpressionFactory().
+                                createMethodExpression(context.getELContext(),
+                                        attributeExpressionString, Void.TYPE, 
+                                        new Class[]{ValueChangeEvent.class});
 
-                            ((EditableValueHolder)innerComponent).addValueChangeListener(
-                                    new MethodExpressionValueChangeListener(methodExpression));
-                        }
-                        else
-                        {
-                            methodSignature = methodSignature.trim();
-                            methodExpression = context.getApplication().getExpressionFactory().
-                            createMethodExpression(context.getELContext(),
-                                    attributeExpressionString, _getReturnType(methodSignature),

-                                    _getParameters(methodSignature));
-                            
-                            innerComponent.getAttributes().put(attributeName, methodExpression);
+                                ((EditableValueHolder)innerComponent).addValueChangeListener(
+                                        new MethodExpressionValueChangeListener(methodExpression));
+                            }
                         }
                     }
+                    else
+                    {
+                        // composite:attribute targets property only has sense for action,
actionListener,
+                        // validator or valueChangeListener. This means we have to retarget
the method expression
+                        // to the topLevelComponent.
+                        methodSignature = methodSignature.trim();
+                        methodExpression = context.getApplication().getExpressionFactory().
+                        createMethodExpression(context.getELContext(),
+                                attributeExpressionString, _getReturnType(methodSignature),

+                                _getParameters(methodSignature));
+                        topLevelComponent.getAttributes().put(attributeName, methodExpression);
+                    }
                 }
             }
         }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java?rev=909661&r1=909660&r2=909661&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentResourceTagHandler.java
Fri Feb 12 23:38:34 2010
@@ -109,21 +109,10 @@
                 ValueExpression ve = (ValueExpression) propertyDescriptor.getValue("required");
                 if (ve != null)
                 {
-                    Object value = ve.getValue (facesContext.getELContext());
-                    Boolean required = null;
-                    
-                    // FIXME: almost positive that the value expression is supposed to evaluate
to a boolean, but originally
+                    // QUESTION: Almost positive that the value expression is supposed to
evaluate to a boolean, but originally
                     // the code assumed it to be a string.  Can someone verify what the right
type is?
-                    
-                    if (value instanceof Boolean)
-                    {
-                        required = (Boolean) value;
-                    }
-                    
-                    else
-                    {
-                        required = Boolean.valueOf((String) value);
-                    }
+                    // ANS: -= Leonardo Uribe =- Take a look at AttributeHandler. The correct
type is Boolean, so we can cast safe 
+                    Boolean required = (Boolean) ve.getValue (facesContext.getELContext());
                     
                     if (required != null && required.booleanValue())
                     {

Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentTestCase.java?rev=909661&r1=909660&r2=909661&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentTestCase.java
(original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/tag/composite/CompositeComponentTestCase.java
Fri Feb 12 23:38:34 2010
@@ -153,7 +153,8 @@
         UICommand button = (UICommand) compositeComponent.findComponent("button");
         assertNotNull(button);
         assertEquals("#{helloWorldBean.send}", button.getActionExpression().getExpressionString());
-        assertEquals("#{helloWorldBean.send}", ((MethodExpression)button.getAttributes().get("metodo")).getExpressionString());
+        assertEquals("#{helloWorldBean.send}", ((MethodExpression)compositeComponent.getAttributes().get("metodo")).getExpressionString());
+        assertNull(button.getAttributes().get("metodo"));
         
         UICommand link = (UICommand) compositeComponent.findComponent("link");
         assertNotNull(link);

Modified: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleAttributeMethodExpression.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleAttributeMethodExpression.xhtml?rev=909661&r1=909660&r2=909661&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleAttributeMethodExpression.xhtml
(original)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/testComposite/simpleAttributeMethodExpression.xhtml
Fri Feb 12 23:38:34 2010
@@ -26,7 +26,8 @@
     <composite:attribute name="actionListener" targets="link" method-signature="void someAction(javax.faces.event.ActionEvent)"/>
     <composite:attribute name="validator" targets="input" method-signature="void validateSomething(javax.faces.context.FacesContext,javax.faces.component.UIComponent,Object)"/>
     <composite:attribute name="valueChangeListener" targets="input" method-signature="void
afterSomeChange(javax.faces.event.ValueChangeEvent)"/>
-    <composite:attribute name="metodo" targets="button" method-signature="String someAction()"/>
   
+    <!-- Here targets should be ignored, because it is only valid for the previous four
attributes -->
+    <composite:attribute name="metodo" targets="button" method-signature="String someAction()"/>
 </composite:interface>
 <composite:implementation>
     <h:commandButton id="button" action="#{cc.attrs.action}" value="Press Me" />



Mime
View raw message