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/10/29 02:57:19 UTC

svn commit: r1028566 - in /myfaces/core/trunk/impl/src: main/java/org/apache/myfaces/view/facelets/ main/java/org/apache/myfaces/view/facelets/impl/ test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/

Author: lu4242
Date: Fri Oct 29 00:57:19 2010
New Revision: 1028566

URL: http://svn.apache.org/viewvc?rev=1028566&view=rev
Log:
MYFACES-2946 composite:attribute "targets" property does not match with ViewDeclarationLanguage.retargetMethodExpressions

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java
    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/impl/FaceletCompositionContextImpl.java
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/compositeActionMethodInvocation.xhtml

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java?rev=1028566&r1=1028565&r2=1028566&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletCompositionContext.java Fri Oct 29 00:57:19 2010
@@ -289,30 +289,49 @@ abstract public class FaceletComposition
     /**
      * Add a method expression as targeted for the provided composite component
      * 
-     * @since 2.0.2
+     * @since 2.0.3
      * @param compositeComponentParent
      * @param attributeName
      * @param backingValue A value that could be useful to revert its effects.
      */
-    public abstract void addMethodExpressionTargeted(UIComponent compositeComponentParent, String attributeName, Object backingValue);
-    
+    public abstract void addMethodExpressionTargeted(UIComponent targetedComponent, String attributeName, Object backingValue);
+
     /**
-     * Get all method expressions targeted for the provided composite component
+     * Check if the MethodExpression attribute has been applied using vdl.retargetMethodExpression 
      * 
-     * @since 2.0.2
+     * @since 2.0.3
      * @param compositeComponentParent
+     * @param attributeName
      * @return
      */
-    public abstract Map<String, Object> getMethodExpressionsTargeted(UIComponent compositeComponentParent);
+    public abstract boolean isMethodExpressionAttributeApplied(UIComponent compositeComponentParent, String attributeName);
+    
+    /**
+     * Mark the MethodExpression attribute as applied using vdl.retargetMethodExpression
+     * 
+     * @since 2.0.3
+     * @param compositeComponentParent
+     * @param attributeName
+     */
+    public abstract void markMethodExpressionAttribute(UIComponent compositeComponentParent, String attributeName);
+    
+    /**
+     * Clear the MethodExpression attribute to call vdl.retargetMethodExpression again
+     * 
+     * @since 2.0.3
+     * @param compositeComponentParent
+     * @param attributeName
+     */
+    public abstract void clearMethodExpressionAttribute(UIComponent compositeComponentParent, String attributeName);
     
     /**
      * Remove a method expression as targeted for the provided composite component
      * 
-     * @since 2.0.2
+     * @since 2.0.3
      * @param compositeComponentParent
      * @param attributeName
      * @return A value that could be useful to revert its effects.
      */
-    public abstract Object removeMethodExpressionTargeted(UIComponent compositeComponentParent, String attributeName);
+    public abstract Object removeMethodExpressionTargeted(UIComponent targetedComponent, String attributeName);
 
 }

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=1028566&r1=1028565&r2=1028566&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 Oct 29 00:57:19 2010
@@ -876,129 +876,106 @@ public class FaceletViewDeclarationLangu
                 
                 if (isKnownMethod)
                 {
-                    for (String target : targetsArray)
+                    if (!mctx.isMethodExpressionAttributeApplied(topLevelComponent, 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;
-                        }
-                        
-                        Map<String, Object> methodsAlreadyProcessed = mctx.getMethodExpressionsTargeted(innerComponent);
-                        
-                        if ("action".equals(attributeName))
-                        {
-                            if (isCompositeComponentRetarget(context, innerComponent, attributeName) && !(innerComponent instanceof ActionSource2))
-                            {
-                                innerComponent.getAttributes().put(attributeName, attributeNameValueExpression);
-                          
-                                mctx.removeMethodExpressionTargeted(innerComponent, attributeName);
-                                
-                                retargetMethodExpressions(context, innerComponent);
-                            }
-                            else if (!methodsAlreadyProcessed.containsKey(attributeName))
+                            UIComponent innerComponent = topLevelComponent.findComponent(target);
+                            
+                            if (innerComponent == null)
                             {
-                                // target is ActionSource2
-                                methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory().
-                                        createMethodExpression(elContext,
-                                                attributeExpressionString, null, EMPTY_CLASS_ARRAY), attributeNameValueExpression);
-                                
-                                ((ActionSource2)innerComponent).setActionExpression(methodExpression);
-                                mctx.addMethodExpressionTargeted(topLevelComponent, attributeName, methodExpression);
+                                if (log.isLoggable(Level.SEVERE))
+                                    log.severe("Inner component " + target + " not found when retargetMethodExpressions");
+                                continue;
                             }
-                        }
-                        else if ("actionListener".equals(attributeName))
-                        {
-                            if (isCompositeComponentRetarget(context, innerComponent, attributeName) && !(innerComponent instanceof ActionSource2))
+                            
+                            if (isCompositeComponentRetarget(context, innerComponent, attributeName))
                             {
                                 innerComponent.getAttributes().put(attributeName, attributeNameValueExpression);
                                 
-                                ActionListener o = (ActionListener) mctx.removeMethodExpressionTargeted(innerComponent, attributeName);
-                                if (o != null)
-                                {
-                                    ((ActionSource2)innerComponent).removeActionListener(o);
-                                }
+                                mctx.clearMethodExpressionAttribute(innerComponent, attributeName);
                                 
                                 retargetMethodExpressions(context, innerComponent);
                             }
-                            else if (!methodsAlreadyProcessed.containsKey(attributeName))
-                            {
-                                // target is ActionSource2
-                                methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory().
-                                        createMethodExpression(elContext,
-                                                attributeExpressionString, Void.TYPE, ACTION_LISTENER_SIGNATURE), attributeNameValueExpression);
-                                
-                                methodExpression2 = reWrapMethodExpression(context.getApplication().getExpressionFactory().
-                                    createMethodExpression(elContext,
-                                            attributeExpressionString, Void.TYPE, EMPTY_CLASS_ARRAY), attributeNameValueExpression);
-                                
-                                ActionListener actionListener = new MethodExpressionActionListener(methodExpression, methodExpression2);
-                                ((ActionSource2)innerComponent).addActionListener(actionListener);
-                                mctx.addMethodExpressionTargeted(topLevelComponent, attributeName, actionListener);
-                            }
-                        }
-                        else if ("validator".equals(attributeName))
-                        {
-                            if (isCompositeComponentRetarget(context, innerComponent, attributeName) && !(innerComponent instanceof EditableValueHolder))
+                            else
                             {
-                                innerComponent.getAttributes().put(attributeName, attributeNameValueExpression);
-                                
-                                Validator o = (Validator) mctx.removeMethodExpressionTargeted(innerComponent, attributeName);
-                                if (o != null)
+                                if ("action".equals(attributeName))
                                 {
-                                    ((EditableValueHolder)innerComponent).removeValidator(o);
+                                    // target is ActionSource2
+                                    methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory().
+                                            createMethodExpression(elContext,
+                                                    attributeExpressionString, null, EMPTY_CLASS_ARRAY), attributeNameValueExpression);
+                                    
+                                    ((ActionSource2)innerComponent).setActionExpression(methodExpression);
                                 }
-                                
-                                retargetMethodExpressions(context, innerComponent);
-                            }
-                            else if (!methodsAlreadyProcessed.containsKey(attributeName))
-                            {
-                                // target is EditableValueHolder
-                                methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory().
-                                        createMethodExpression(elContext,
-                                            attributeExpressionString, Void.TYPE, 
-                                            VALIDATOR_SIGNATURE), attributeNameValueExpression);
-    
-                                Validator validator = new MethodExpressionValidator(methodExpression); 
-                                ((EditableValueHolder)innerComponent).addValidator( validator );
-                                mctx.addMethodExpressionTargeted(topLevelComponent, attributeName, validator);
-                            }
-                        }
-                        else if ("valueChangeListener".equals(attributeName))
-                        {
-                            if (isCompositeComponentRetarget(context, innerComponent, attributeName) && !(innerComponent instanceof EditableValueHolder))
-                            {
-                                innerComponent.getAttributes().put(attributeName, attributeNameValueExpression);
-
-                                ValueChangeListener o = (ValueChangeListener) mctx.removeMethodExpressionTargeted(innerComponent, attributeName);
-                                if (o != null)
+                                else if ("actionListener".equals(attributeName))
                                 {
-                                    ((EditableValueHolder)innerComponent).removeValueChangeListener(o);
-                                }
-                                
-                                retargetMethodExpressions(context, innerComponent);
-                            }
-                            else if (!methodsAlreadyProcessed.containsKey(attributeName))
-                            {
-                                // target is EditableValueHolder
-                                methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory().
-                                        createMethodExpression(elContext,
-                                                attributeExpressionString, Void.TYPE, 
-                                                VALUE_CHANGE_LISTENER_SIGNATURE), attributeNameValueExpression);
-    
-                                methodExpression2 = reWrapMethodExpression(context.getApplication().getExpressionFactory().
+                                    //First try to remove any prevous target if any
+                                    ActionListener o = (ActionListener) mctx.removeMethodExpressionTargeted(innerComponent, attributeName);
+                                    if (o != null)
+                                    {
+                                        ((ActionSource2)innerComponent).removeActionListener(o);
+                                    }
+                                    
+                                    // target is ActionSource2
+                                    methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory().
+                                            createMethodExpression(elContext,
+                                                    attributeExpressionString, Void.TYPE, ACTION_LISTENER_SIGNATURE), attributeNameValueExpression);
+                                    
+                                    methodExpression2 = reWrapMethodExpression(context.getApplication().getExpressionFactory().
                                         createMethodExpression(elContext,
+                                                attributeExpressionString, Void.TYPE, EMPTY_CLASS_ARRAY), attributeNameValueExpression);
+                                    
+                                    ActionListener actionListener = new MethodExpressionActionListener(methodExpression, methodExpression2);
+                                    ((ActionSource2)innerComponent).addActionListener(actionListener);
+                                    mctx.addMethodExpressionTargeted(innerComponent, attributeName, actionListener);
+                                }
+                                else if ("validator".equals(attributeName))
+                                {
+                                   //First try to remove any prevous target if any
+                                    Validator o = (Validator) mctx.removeMethodExpressionTargeted(innerComponent, attributeName);
+                                    if (o != null)
+                                    {
+                                        ((EditableValueHolder)innerComponent).removeValidator(o);
+                                    }
+                                    
+                                    // target is EditableValueHolder
+                                    methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory().
+                                            createMethodExpression(elContext,
                                                 attributeExpressionString, Void.TYPE, 
-                                                EMPTY_CLASS_ARRAY), attributeNameValueExpression);
-    
-                                ValueChangeListener valueChangeListener = new MethodExpressionValueChangeListener(methodExpression, methodExpression2); 
-                                ((EditableValueHolder)innerComponent).addValueChangeListener( valueChangeListener );
-                                mctx.addMethodExpressionTargeted(topLevelComponent, attributeName, valueChangeListener);
+                                                VALIDATOR_SIGNATURE), attributeNameValueExpression);
+        
+                                    Validator validator = new MethodExpressionValidator(methodExpression); 
+                                    ((EditableValueHolder)innerComponent).addValidator( validator );
+                                    mctx.addMethodExpressionTargeted(innerComponent, attributeName, validator);
+                                }
+                                else if ("valueChangeListener".equals(attributeName))
+                                {
+                                    ValueChangeListener o = (ValueChangeListener) mctx.removeMethodExpressionTargeted(innerComponent, attributeName);
+                                    if (o != null)
+                                    {
+                                        ((EditableValueHolder)innerComponent).removeValueChangeListener(o);
+                                    }
+                                    
+                                    // target is EditableValueHolder
+                                    methodExpression = reWrapMethodExpression(context.getApplication().getExpressionFactory().
+                                            createMethodExpression(elContext,
+                                                    attributeExpressionString, Void.TYPE, 
+                                                    VALUE_CHANGE_LISTENER_SIGNATURE), attributeNameValueExpression);
+        
+                                    methodExpression2 = reWrapMethodExpression(context.getApplication().getExpressionFactory().
+                                            createMethodExpression(elContext,
+                                                    attributeExpressionString, Void.TYPE, 
+                                                    EMPTY_CLASS_ARRAY), attributeNameValueExpression);
+        
+                                    ValueChangeListener valueChangeListener = new MethodExpressionValueChangeListener(methodExpression, methodExpression2); 
+                                    ((EditableValueHolder)innerComponent).addValueChangeListener( valueChangeListener );
+                                    mctx.addMethodExpressionTargeted(innerComponent, attributeName, valueChangeListener);
+                                }
                             }
                         }
+                        
+                        mctx.markMethodExpressionAttribute(topLevelComponent, attributeName);
                     }
                 }
                 else
@@ -1032,7 +1009,7 @@ public class FaceletViewDeclarationLangu
                         {
                             innerComponent.getAttributes().put(attributeName, attributeNameValueExpression);
                             
-                            mctx.removeMethodExpressionTargeted(innerComponent, attributeName);
+                            mctx.clearMethodExpressionAttribute(innerComponent, attributeName);
                             
                             retargetMethodExpressions(context, innerComponent);
                         }
@@ -1042,10 +1019,9 @@ public class FaceletViewDeclarationLangu
                             innerComponent.getAttributes().put(attributeName, methodExpression);
                         }
                     }
-
                     //Store the method expression to the topLevelComponent to allow reference it through EL
                     topLevelComponent.getAttributes().put(attributeName, methodExpression);
-                    mctx.addMethodExpressionTargeted(topLevelComponent, attributeName, methodExpression);
+                    mctx.markMethodExpressionAttribute(topLevelComponent, attributeName);
                 }
                 
                 // We need to remove the previous ValueExpression, to prevent some possible
@@ -1094,7 +1070,26 @@ public class FaceletViewDeclarationLangu
                     // either the attributeName has to be a knownMethod or there has to be a method-signature
                     if (isKnownMethod || methodSignature != null)
                     {
-                        return true;
+                        if ("action".equals(attributeName))
+                        {
+                            return !(component instanceof ActionSource2);
+                        }
+                        else if ("actionListener".equals(attributeName))
+                        {
+                            return !(component instanceof ActionSource2);
+                        }
+                        else if ("validator".equals(attributeName))
+                        {
+                            return !(component instanceof EditableValueHolder);
+                        }
+                        else if ("valueChangeListener".equals(attributeName))
+                        {
+                            return !(component instanceof EditableValueHolder);
+                        }
+                        else
+                        {
+                            return true;
+                        }
                     }
                 }
             }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java?rev=1028566&r1=1028565&r2=1028566&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/impl/FaceletCompositionContextImpl.java Fri Oct 29 00:57:19 2010
@@ -73,6 +73,8 @@ public class FaceletCompositionContextIm
     private final Map<UIComponent, List<AttachedObjectHandler>> _attachedObjectHandlers;
     
     private final Map<UIComponent, Map<String, Object> > _methodExpressionsTargeted;
+    
+    private final Map<UIComponent, Map<String, Boolean> > _compositeComponentAttributesMarked;
 
     private static final String VIEWROOT_FACELET_ID = "oam.VIEW_ROOT";
     
@@ -84,6 +86,7 @@ public class FaceletCompositionContextIm
         _attachedObjectHandlers = new HashMap<UIComponent, List<AttachedObjectHandler>>();
         _componentsMarkedForDeletion = new ArrayList<Map<String,UIComponent>>();
         _methodExpressionsTargeted = new HashMap<UIComponent, Map<String, Object>>();
+        _compositeComponentAttributesMarked = new HashMap<UIComponent, Map<String, Boolean>>();
         _deletionLevel = -1;
     }
 
@@ -372,19 +375,20 @@ public class FaceletCompositionContextIm
     }
     
     @Override
-    public void addMethodExpressionTargeted(UIComponent compositeComponentParent, String attributeName, Object backingValue)
+    public void addMethodExpressionTargeted(UIComponent targetedComponent, String attributeName, Object backingValue)
     {
-        Map<String, Object> map = _methodExpressionsTargeted.get(compositeComponentParent);
+        Map<String, Object> map = _methodExpressionsTargeted.get(targetedComponent);
 
         if (map == null)
         {
             map = new HashMap<String, Object>(8);
-            _methodExpressionsTargeted.put(compositeComponentParent, map);
+            _methodExpressionsTargeted.put(targetedComponent, map);
         }
 
         map.put(attributeName, backingValue);
     }
 
+    /*
     @Override
     public Map<String, Object> getMethodExpressionsTargeted(UIComponent compositeComponentParent)
     {
@@ -394,12 +398,47 @@ public class FaceletCompositionContextIm
             map = Collections.emptyMap();
         }
         return map;
+    }*/
+    
+    public boolean isMethodExpressionAttributeApplied(UIComponent compositeComponentParent, String attributeName)
+    {
+        Map<String, Boolean> map = _compositeComponentAttributesMarked.get(compositeComponentParent);
+        if (map == null)
+        {
+            return false;
+        }
+        Boolean v = map.get(attributeName);
+        return v == null ? false : v.booleanValue();
+    }
+    
+    public void markMethodExpressionAttribute(UIComponent compositeComponentParent, String attributeName)
+    {
+        Map<String, Boolean> map = _compositeComponentAttributesMarked.get(compositeComponentParent);
+        if (map == null)
+        {
+            map = new HashMap<String, Boolean>(8);
+            _compositeComponentAttributesMarked.put(compositeComponentParent, map);
+        }
+        map.put(attributeName, Boolean.TRUE);
+        
     }
     
+    public void clearMethodExpressionAttribute(UIComponent compositeComponentParent, String attributeName)
+    {
+        Map<String, Boolean> map = _compositeComponentAttributesMarked.get(compositeComponentParent);
+        if (map == null)
+        {
+            //No map, so just return
+            return;
+        }
+        map.put(attributeName, Boolean.FALSE);
+    }
+    
+    
     @Override
-    public Object removeMethodExpressionTargeted(UIComponent compositeComponentParent, String attributeName)
+    public Object removeMethodExpressionTargeted(UIComponent targetedComponent, String attributeName)
     {
-        Map<String, Object> map = _methodExpressionsTargeted.get(compositeComponentParent);
+        Map<String, Object> map = _methodExpressionsTargeted.get(targetedComponent);
         if (map != null)
         {
             return map.remove(attributeName);

Modified: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/compositeActionMethodInvocation.xhtml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/compositeActionMethodInvocation.xhtml?rev=1028566&r1=1028565&r2=1028566&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/compositeActionMethodInvocation.xhtml (original)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/view/facelets/tag/composite/resources/testComposite/compositeActionMethodInvocation.xhtml Fri Oct 29 00:57:19 2010
@@ -28,7 +28,7 @@
  <composite:attribute name="actionListener" targets="button1"/>
 </composite:interface>
 <composite:implementation>
- <testComposite:simpleActionMethodInvocation id="button1" value="#{cc.attrs.value}" action="nothing"/>
+ <testComposite:simpleActionMethodInvocation id="button1" value="#{cc.attrs.value}" actionListener="#{helloWorldBean.actionListener}" action="nothing"/>
 </composite:implementation>
 </body>
 </html>
\ No newline at end of file