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 2013/05/12 19:59:19 UTC

svn commit: r1481617 - /myfaces/core/branches/2.1.x-client-window/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java

Author: lu4242
Date: Sun May 12 17:59:19 2013
New Revision: 1481617

URL: http://svn.apache.org/r1481617
Log:
MYFACES-3721 Override of uniqueIdCounter for UIViewRoot in restoreView cause component duplicate id exception

Modified:
    myfaces/core/branches/2.1.x-client-window/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java

Modified: myfaces/core/branches/2.1.x-client-window/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x-client-window/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java?rev=1481617&r1=1481616&r2=1481617&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x-client-window/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java (original)
+++ myfaces/core/branches/2.1.x-client-window/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java Sun May 12 17:59:19 2013
@@ -302,6 +302,9 @@ public class DefaultFaceletsStateManagem
             if (state != null && state[1] != null)
             {
                 states = (Map<String, Object>) state[1];
+                //Save the last unique id counter key in UIViewRoot
+                Long lastUniqueIdCounter = (Long) view.getAttributes().get(UNIQUE_ID_COUNTER_KEY);
+                
                 // Visit the children and restore their state.
                 boolean emptyState = false;
                 boolean containsFaceletState = states.containsKey(
@@ -344,6 +347,18 @@ public class DefaultFaceletsStateManagem
                 {
                     view.getAttributes().put(ComponentSupport.FACELET_STATE_INSTANCE,  faceletViewState);
                 }
+                if (lastUniqueIdCounter != null)
+                {
+                    Long newUniqueIdCounter = (Long) view.getAttributes().get(UNIQUE_ID_COUNTER_KEY);
+                    if (newUniqueIdCounter != null && 
+                        lastUniqueIdCounter.longValue() > newUniqueIdCounter.longValue())
+                    {
+                        // The unique counter was restored by a side effect of 
+                        // restoreState() over UIViewRoot with a lower count,
+                        // to avoid a component duplicate id exception we need to fix the count.
+                        view.getAttributes().put(UNIQUE_ID_COUNTER_KEY, lastUniqueIdCounter);
+                    }
+                }
                 handleDynamicAddedRemovedComponents(context, view, states);
             }
         }