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 2009/06/26 03:53:01 UTC

svn commit: r788560 - /myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/component/UIViewRoot.java

Author: lu4242
Date: Fri Jun 26 01:53:01 2009
New Revision: 788560

URL: http://svn.apache.org/viewvc?rev=788560&view=rev
Log:
MYFACES-2124 Enforce new API on UIViewRoot (correct getComponentResources, addComponentResources and removeComponentResources with the same behavior as ri)

Modified:
    myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/component/UIViewRoot.java

Modified: myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/component/UIViewRoot.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/component/UIViewRoot.java?rev=788560&r1=788559&r2=788560&view=diff
==============================================================================
--- myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/component/UIViewRoot.java (original)
+++ myfaces/core/branches/2_0_0/api/src/main/java/javax/faces/component/UIViewRoot.java Fri Jun 26 01:53:01 2009
@@ -139,15 +139,19 @@
         }
 
         // Call getComponentResources to obtain the child list for the given target
-        List<UIComponent> componentResources = getComponentResources(context, target);
+        List<UIComponent> componentResources = _getComponentResources(context, target);
 
         // If the component ID of componentResource matches the the ID of a resource that has already been added, remove the old resource.
         String componentId = componentResource.getId();
-        for(UIComponent component : componentResources)
+        
+        if (componentId != null)
         {
-            if(componentId.equals(component.getId()))
+            for(UIComponent component : componentResources)
             {
-                componentResources.remove(component);
+                if(componentId.equals(component.getId()))
+                {
+                    componentResources.remove(component);
+                }
             }
         }
         
@@ -401,6 +405,7 @@
         // Locate the facet for the component by calling getFacet() using target as the argument
         UIComponent facet = getFacet(target);
 
+        /*
         // If the facet is not found,
         if (facet == null)
         {
@@ -419,6 +424,33 @@
         // and also that "If no children are found for the facet, return Collections.emptyList()."
         List<UIComponent> children = facet.getChildren();
         return ( children == null ? Collections.<UIComponent>emptyList() : Collections.unmodifiableList(children) );
+        */
+        if (facet != null)
+        {
+            List<UIComponent> children = facet.getChildren();
+            return ( children == null ? Collections.<UIComponent>emptyList() : Collections.unmodifiableList(children) );
+        }
+        return Collections.<UIComponent>emptyList();
+    }
+    
+    private List<UIComponent> _getComponentResources(FacesContext context, String target)
+    {
+        // Locate the facet for the component by calling getFacet() using target as the argument
+        UIComponent facet = getFacet(target);
+
+        // If the facet is not found,
+        if (facet == null)
+        {
+            // create the facet by calling context.getApplication().createComponent()  using javax.faces.Panel as the argument
+            facet = context.getApplication().createComponent("javax.faces.Panel");
+
+            // Set the id of the facet to be target
+            facet.setId(target);
+
+            // Add the facet to the facets Map using target as the key
+            getFacets().put(target, facet);
+        }
+        return facet.getChildren();
     }
 
     @Override
@@ -868,11 +900,19 @@
             }
         }
 
-        // Call getComponentResources to obtain the child list for the given target.
-        List<UIComponent> componentResources = getComponentResources(context, target);
 
-        // Remove the component resource from the child list
-        componentResources.remove(componentResource);
+        // Call getComponentResources to obtain the child list for the given target.
+        //List<UIComponent> componentResources = getComponentResources(context, target);
+        UIComponent facet = getFacet(target);
+        if (facet != null)
+        {
+            //Only if the facet is found it is possible to remove the resource,
+            //otherwise nothing should happen (call to getComponentResource trigger
+            //creation of facet)
+            List<UIComponent> componentResources = facet.getChildren();
+            // Remove the component resource from the child list
+            componentResources.remove(componentResource);
+        }
     }
 
     public void setViewId(String viewId)