myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r881927 - in /myfaces/core/trunk/api/src: main/java/javax/faces/component/_ComponentChildrenList.java test/java/javax/faces/component/UIComponentBaseGetChildrenTest.java
Date Wed, 18 Nov 2009 20:40:02 GMT
Author: lu4242
Date: Wed Nov 18 20:40:02 2009
New Revision: 881927

URL: http://svn.apache.org/viewvc?rev=881927&view=rev
Log:
MYFACES-2407 _ComponentChildrenList does not implement all List methods

Added:
    myfaces/core/trunk/api/src/test/java/javax/faces/component/UIComponentBaseGetChildrenTest.java
Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentChildrenList.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentChildrenList.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentChildrenList.java?rev=881927&r1=881926&r2=881927&view=diff
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentChildrenList.java
(original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_ComponentChildrenList.java
Wed Nov 18 20:40:02 2009
@@ -54,11 +54,11 @@
     public UIComponent set(int index, UIComponent value)
     {
         checkValue(value);
-        
+        removeChildrenFromParent(value);
         UIComponent child = _list.set(index, value);
         if (child != value)
         {
-            childAdded(value);
+            updateParent(value);
             if (child != null)
             {
                 child.setParent(null);
@@ -72,10 +72,11 @@
     public boolean add(UIComponent value)
     {
         checkValue(value);
-        
+
+        removeChildrenFromParent(value);
         boolean res = _list.add(value);
         
-        childAdded(value);
+        updateParent(value);
         
         return res;
     }
@@ -85,9 +86,11 @@
     {
         checkValue(value);
         
+        removeChildrenFromParent(value);
+        
         _list.add(index, value);
         
-        childAdded(value);
+        updateParent(value);
     }
 
     @Override
@@ -115,11 +118,6 @@
         }
     }
 
-    private void childAdded(UIComponent child)
-    {
-        updateParent(child);
-    }
-
     private void childRemoved(UIComponent child)
     {
         child.setParent(null);
@@ -127,18 +125,28 @@
 
     private void updateParent(UIComponent child)
     {
+        child.setParent(_component);
+    }
+    
+    private void removeChildrenFromParent(UIComponent child)
+    {
         UIComponent oldParent = child.getParent();
         if (oldParent != null)
         {
             oldParent.getChildren().remove(child);
         }
-        
-        child.setParent(_component);
     }
 
     @Override
-    public boolean remove(Object o)
+    public boolean remove(Object value)
     {
-        return _list.remove(o);
+        checkValue(value);
+        
+        if (_list.remove(value))
+        {
+            childRemoved((UIComponent)value);
+            return true;
+        }
+        return false;
     }
 }

Added: myfaces/core/trunk/api/src/test/java/javax/faces/component/UIComponentBaseGetChildrenTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/test/java/javax/faces/component/UIComponentBaseGetChildrenTest.java?rev=881927&view=auto
==============================================================================
--- myfaces/core/trunk/api/src/test/java/javax/faces/component/UIComponentBaseGetChildrenTest.java
(added)
+++ myfaces/core/trunk/api/src/test/java/javax/faces/component/UIComponentBaseGetChildrenTest.java
Wed Nov 18 20:40:02 2009
@@ -0,0 +1,89 @@
+/*
+ * 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 javax.faces.component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.shale.test.base.AbstractJsfTestCase;
+
+public class UIComponentBaseGetChildrenTest extends AbstractJsfTestCase
+{
+
+    public UIComponentBaseGetChildrenTest(String name)
+    {
+        super(name);
+    }
+
+    @Override
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+    }
+
+    @Override
+    protected void tearDown() throws Exception
+    {
+        super.tearDown();
+    }
+    
+    public void testGetChildrenAddAll()
+    {
+        UIInput input0 = new UIInput();
+        UIInput input1 = new UIInput();
+        UIInput input2 = new UIInput();
+        UIInput input3 = new UIInput();
+        
+        //Set Ids to identify them
+        input0.setId("input0");
+        input1.setId("input1");
+        input2.setId("input2");
+        input3.setId("input3");
+        
+        UIPanel panel = new UIPanel();
+        
+        List<UIComponent> children = panel.getChildren();
+        children.add(0, input0);
+        children.add(input1);
+        
+        List<UIComponent> list = new ArrayList<UIComponent>();
+        list.add(input2);
+        list.add(input3);
+
+        children.addAll(list);
+        // Add again, it should be removed from last positions and
+        // inserted to the first ones
+        children.addAll(0, list);
+        
+        assertEquals(4, children.size());
+        assertEquals(input2.getId(), children.get(0).getId());
+        assertEquals(input3.getId(), children.get(1).getId());
+    }
+    
+    public void testSimpleAddRemove()
+    {
+        UIInput input = new UIInput();
+        input.setId("input0");
+        UIPanel panel = new UIPanel();
+        panel.getChildren().add(input);
+        assertEquals(panel, input.getParent());
+        panel.getChildren().remove(input);
+        assertNull(input.getParent());
+    }
+}



Mime
View raw message