Return-Path: Delivered-To: apmail-myfaces-commits-archive@www.apache.org Received: (qmail 62989 invoked from network); 2 Oct 2010 17:15:23 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 2 Oct 2010 17:15:23 -0000 Received: (qmail 44128 invoked by uid 500); 2 Oct 2010 17:15:23 -0000 Delivered-To: apmail-myfaces-commits-archive@myfaces.apache.org Received: (qmail 44020 invoked by uid 500); 2 Oct 2010 17:15:22 -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 44013 invoked by uid 99); 2 Oct 2010 17:15:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 02 Oct 2010 17:15:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED 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; Sat, 02 Oct 2010 17:15:21 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8F3902388A38; Sat, 2 Oct 2010 17:15:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1003837 - /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java Date: Sat, 02 Oct 2010 17:15:01 -0000 To: commits@myfaces.apache.org From: lu4242@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101002171501.8F3902388A38@eris.apache.org> Author: lu4242 Date: Sat Oct 2 17:15:01 2010 New Revision: 1003837 URL: http://svn.apache.org/viewvc?rev=1003837&view=rev Log: MYFACES-2935 SystemEvent Acid Test (prevent add components twice on restore and remove duplicate ids) Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java?rev=1003837&r1=1003836&r2=1003837&view=diff ============================================================================== --- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java (original) +++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java Sat Oct 2 17:15:01 2010 @@ -52,6 +52,7 @@ import javax.faces.view.ViewMetadata; import org.apache.myfaces.shared_impl.renderkit.RendererUtils; import org.apache.myfaces.shared_impl.util.ClassUtils; +import org.apache.myfaces.shared_impl.util.HashMapUtils; /** * This class implements partial state saving feature when facelets @@ -225,91 +226,105 @@ public class DefaultFaceletsStateManagem if (clientIdsRemoved != null) { + Set idsRemovedSet = new HashSet(HashMapUtils.calcCapacity(clientIdsRemoved.size())); for (String clientId : clientIdsRemoved) { - view.invokeOnComponent(context, clientId, new ContextCallback() - { - public void invokeContextCallback(FacesContext context, - UIComponent target) + if (!idsRemovedSet.contains(clientId)) + { + view.invokeOnComponent(context, clientId, new ContextCallback() { - if (target.getParent() != null) + public void invokeContextCallback(FacesContext context, + UIComponent target) { - if (!target.getParent().getChildren().remove(target)) + if (target.getParent() != null) { - String key = null; - for (Map.Entry entry : target.getParent().getFacets().entrySet()) + if (!target.getParent().getChildren().remove(target)) { - if (entry.getValue()==target) + String key = null; + for (Map.Entry entry : target.getParent().getFacets().entrySet()) { - key = entry.getKey(); - break; + if (entry.getValue()==target) + { + key = entry.getKey(); + break; + } + } + if (key != null) + { + target.getParent().getFacets().remove(key); } - } - if (key != null) - { - target.getParent().getFacets().remove(key); } } } - } - }); + }); + idsRemovedSet.add(clientId); + } } + clientIdsRemoved.clear(); + clientIdsRemoved.addAll(idsRemovedSet); } List clientIdsAdded = getClientIdsAdded(view); if (clientIdsAdded != null) { + Set idsAddedSet = new HashSet(HashMapUtils.calcCapacity(clientIdsAdded.size())); for (String clientId : clientIdsAdded) { - final AttachedFullStateWrapper wrapper = (AttachedFullStateWrapper) states.get(clientId); - if (wrapper != null) + if (!idsAddedSet.contains(clientId)) { - final Object[] addedState = (Object[]) wrapper.getWrappedStateObject(); - if (addedState != null) + final AttachedFullStateWrapper wrapper = (AttachedFullStateWrapper) states.get(clientId); + if (wrapper != null) { - if (addedState.length == 2) + final Object[] addedState = (Object[]) wrapper.getWrappedStateObject(); + if (addedState != null) { - view = (UIViewRoot) internalRestoreTreeStructure((TreeStructComponent) addedState[0]); - view.processRestoreState(context, addedState[1]); - break; - } - else - { - final String parentClientId = (String) addedState[0]; - view.invokeOnComponent(context, parentClientId, new ContextCallback() + if (addedState.length == 2) + { + view = (UIViewRoot) internalRestoreTreeStructure((TreeStructComponent) addedState[0]); + view.processRestoreState(context, addedState[1]); + break; + } + else { - public void invokeContextCallback(FacesContext context, - UIComponent target) + final String parentClientId = (String) addedState[0]; + view.invokeOnComponent(context, parentClientId, new ContextCallback() { - if (addedState[1] != null) + public void invokeContextCallback(FacesContext context, + UIComponent target) { - String facetName = (String) addedState[1]; - UIComponent child = internalRestoreTreeStructure((TreeStructComponent) addedState[3]); - child.processRestoreState(context, addedState[4]); - target.getFacets().put(facetName,child); - } - else - { - Integer childIndex = (Integer) addedState[2]; - UIComponent child = internalRestoreTreeStructure((TreeStructComponent) addedState[3]); - child.processRestoreState(context, addedState[4]); - try + if (addedState[1] != null) { - target.getChildren().add(childIndex, child); + String facetName = (String) addedState[1]; + UIComponent child = internalRestoreTreeStructure((TreeStructComponent) addedState[3]); + child.processRestoreState(context, addedState[4]); + target.getFacets().put(facetName,child); } - catch (IndexOutOfBoundsException e) + else { - // We can't be sure about where should be this - // item, so just add it. - target.getChildren().add(child); + Integer childIndex = (Integer) addedState[2]; + UIComponent child = internalRestoreTreeStructure((TreeStructComponent) addedState[3]); + child.processRestoreState(context, addedState[4]); + try + { + target.getChildren().add(childIndex, child); + } + catch (IndexOutOfBoundsException e) + { + // We can't be sure about where should be this + // item, so just add it. + target.getChildren().add(child); + } } } - } - }); + }); + } } } + idsAddedSet.add(clientId); } } + clientIdsAdded.clear(); + clientIdsAdded.addAll(idsAddedSet); } } }