myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r906311 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets: ComponentState.java DefaultFaceletsStateManagementStrategy.java tag/jsf/ComponentSupport.java
Date Thu, 04 Feb 2010 00:49:00 GMT
Author: lu4242
Date: Thu Feb  4 00:48:59 2010
New Revision: 906311

URL: http://svn.apache.org/viewvc?rev=906311&view=rev
Log:
MYFACES-2532 getClientId() should not be called from listener registering tree changes on
DefaultFaceletsStateManagementStrategy and PostAddToViewEvent

Added:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/ComponentState.java
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/DefaultFaceletsStateManagementStrategy.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/ComponentState.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/ComponentState.java?rev=906311&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/ComponentState.java
(added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/ComponentState.java
Thu Feb  4 00:48:59 2010
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.myfaces.view.facelets;
+
+/**
+ * Enum used inside the key DefaultFaceletsStateManagementStrategy.COMPONENT_ADDED_AFTER_BUILD_VIEW
+ * on the component attribute map to indicate if the component should be
+ * add, removed and add o it was already added to DefaultFaceletsStateManagementStrategy.CLIENTIDS_ADDED
+ * and DefaultFaceletsStateManagementStrategy.CLIENTIDS_REMOVED
+ * 
+ * @author Leonardo Uribe (latest modification by $Author: lu4242 $)
+ * @version $Revision: 793245 $ $Date: 2009-07-11 18:50:53 -0500 (Sat, 11 Jul 2009) $
+ * @since 2.0
+ */
+public enum ComponentState
+{
+    ADD,
+    REMOVE_ADD,
+    ADDED,
+}

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=906311&r1=906310&r2=906311&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
Thu Feb  4 00:48:59 2010
@@ -38,7 +38,6 @@
 import javax.faces.component.visit.VisitResult;
 import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
-import javax.faces.event.ComponentSystemEvent;
 import javax.faces.event.PostAddToViewEvent;
 import javax.faces.event.PostRestoreStateEvent;
 import javax.faces.event.PreRemoveFromViewEvent;
@@ -541,11 +540,27 @@
 
         setClientsIdsRemoved(uiViewRoot, clientIdsRemoved);
     }
+    
+    @SuppressWarnings("unchecked")
+    private void registerOnAddList(String clientId)
+    {
+        UIViewRoot uiViewRoot = FacesContext.getCurrentInstance().getViewRoot();
+
+        List<String> clientIdsAdded = (List<String>) getClientIdsAdded(uiViewRoot);
+        if (clientIdsAdded == null)
+        {
+            //Create a set that preserve insertion order
+            clientIdsAdded = new ArrayList<String>();
+        }
+        clientIdsAdded.add(clientId);
+
+        setClientsIdsAdded(uiViewRoot, clientIdsAdded);
+    }
             
     private void saveStateOnMap(final FacesContext context, final Map<String,Object>
states,
             final UIComponent component)
     {
-        Boolean componentAddedAfterBuildView = null;
+        ComponentState componentAddedAfterBuildView = null;
         try
         {
             component.pushComponentToEL(context, component);
@@ -561,13 +576,18 @@
                     UIComponent child = children.get(i);
                     if (child != null && !child.isTransient())
                     {
-                        componentAddedAfterBuildView = (Boolean) child.getAttributes().get(COMPONENT_ADDED_AFTER_BUILD_VIEW);
+                        componentAddedAfterBuildView = (ComponentState) child.getAttributes().get(COMPONENT_ADDED_AFTER_BUILD_VIEW);
                         if (componentAddedAfterBuildView != null)
                         {
-                            if (Boolean.FALSE.equals(componentAddedAfterBuildView))
+                            if (ComponentState.REMOVE_ADD.equals(componentAddedAfterBuildView))
                             {
                                 registerOnAddRemoveList(child.getClientId());
-                                child.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW,
Boolean.TRUE);
+                                child.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW,
ComponentState.ADDED);
+                            }
+                            else if (ComponentState.ADD.equals(componentAddedAfterBuildView))
+                            {
+                                registerOnAddList(child.getClientId());
+                                child.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW,
ComponentState.ADDED);
                             }
                             ensureClearInitialState(child);
                             //Save all required info to restore the subtree.
@@ -600,13 +620,18 @@
                     if (child != null && !child.isTransient())
                     {
                         String facetName = entry.getKey();
-                        componentAddedAfterBuildView = (Boolean) child.getAttributes().get(COMPONENT_ADDED_AFTER_BUILD_VIEW);
+                        componentAddedAfterBuildView = (ComponentState) child.getAttributes().get(COMPONENT_ADDED_AFTER_BUILD_VIEW);
                         if (componentAddedAfterBuildView != null)
                         {
-                            if (Boolean.FALSE.equals(componentAddedAfterBuildView))
+                            if (ComponentState.REMOVE_ADD.equals(componentAddedAfterBuildView))
                             {
                                 registerOnAddRemoveList(child.getClientId());
-                                child.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW,
Boolean.TRUE);
+                                child.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW,
ComponentState.ADDED);
+                            }
+                            else if (ComponentState.ADD.equals(componentAddedAfterBuildView))
+                            {
+                                registerOnAddList(child.getClientId());
+                                child.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW,
ComponentState.ADDED);
                             }
                             //Save all required info to restore the subtree.
                             //This includes position, structure and state of subtree
@@ -787,6 +812,11 @@
         {
             UIComponent component = (UIComponent) event.getSource();
             
+            if (component.isTransient())
+            {
+                return;
+            }
+            
             FacesContext facesContext = FacesContext.getCurrentInstance();
             if (FaceletViewDeclarationLanguage.isRefreshingTransientBuild(facesContext))
             {
@@ -796,18 +826,7 @@
             if (event instanceof PostAddToViewEvent)
             {
                 //PostAddToViewEvent
-                UIViewRoot uiViewRoot = facesContext.getViewRoot();
-                
-                List<String> clientIdsAdded = getClientIdsAdded(uiViewRoot);
-                if (clientIdsAdded == null)
-                {
-                    //Create a set that preserve insertion order
-                    clientIdsAdded = new ArrayList<String>();
-                }
-                clientIdsAdded.add(component.getClientId());
-                setClientsIdsAdded(uiViewRoot, clientIdsAdded);
-                
-                component.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW, Boolean.TRUE);
+                component.getAttributes().put(COMPONENT_ADDED_AFTER_BUILD_VIEW, ComponentState.ADD);
             }
             else
             {

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java?rev=906311&r1=906310&r2=906311&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/tag/jsf/ComponentSupport.java
Thu Feb  4 00:48:59 2010
@@ -34,6 +34,7 @@
 import javax.faces.view.facelets.TagAttributeException;
 
 import org.apache.myfaces.shared_impl.config.MyfacesConfig;
+import org.apache.myfaces.view.facelets.ComponentState;
 import org.apache.myfaces.view.facelets.DefaultFaceletsStateManagementStrategy;
 import org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage;
 
@@ -424,7 +425,7 @@
     {
         if (MyfacesConfig.getCurrentInstance(context.getExternalContext()).isRefreshTransientBuildOnPSSPreserveState())
         {
-            component.getAttributes().put(DefaultFaceletsStateManagementStrategy.COMPONENT_ADDED_AFTER_BUILD_VIEW,
Boolean.FALSE);
+            component.getAttributes().put(DefaultFaceletsStateManagementStrategy.COMPONENT_ADDED_AFTER_BUILD_VIEW,
ComponentState.REMOVE_ADD);
         }
         //component.subscribeToEvent(PostAddToViewEvent.class, new RestoreComponentFullyListener());
         if (FaceletViewDeclarationLanguage.isRefreshTransientBuildOnPSSAuto(context))



Mime
View raw message