Return-Path: Delivered-To: apmail-myfaces-commits-archive@www.apache.org Received: (qmail 39862 invoked from network); 18 Nov 2009 20:40:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Nov 2009 20:40:26 -0000 Received: (qmail 9020 invoked by uid 500); 18 Nov 2009 20:40:25 -0000 Delivered-To: apmail-myfaces-commits-archive@myfaces.apache.org Received: (qmail 8922 invoked by uid 500); 18 Nov 2009 20:40:25 -0000 Mailing-List: contact commits-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Development" Delivered-To: mailing list commits@myfaces.apache.org Received: (qmail 8913 invoked by uid 99); 18 Nov 2009 20:40:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Nov 2009 20:40:25 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Nov 2009 20:40:23 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 292402388996; Wed, 18 Nov 2009 20:40:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@myfaces.apache.org From: lu4242@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091118204003.292402388996@eris.apache.org> 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 children = panel.getChildren(); + children.add(0, input0); + children.add(input1); + + List list = new ArrayList(); + 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()); + } +}