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 2011/10/05 20:31:14 UTC

svn commit: r1179369 - /myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java

Author: lu4242
Date: Wed Oct  5 18:31:14 2011
New Revision: 1179369

URL: http://svn.apache.org/viewvc?rev=1179369&view=rev
Log:
MYFACES-3312 Compare viewId after PreRenderView does not detect navigation to the same page

Modified:
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java?rev=1179369&r1=1179368&r2=1179369&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/lifecycle/RenderResponseExecutor.java Wed Oct  5 18:31:14 2011
@@ -25,6 +25,7 @@ import java.util.logging.Logger;
 import javax.faces.FacesException;
 import javax.faces.application.Application;
 import javax.faces.application.FacesMessage;
+import javax.faces.application.ProjectStage;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
@@ -48,8 +49,12 @@ class RenderResponseExecutor extends Pha
         Application application = facesContext.getApplication();
         ViewHandler viewHandler = application.getViewHandler();
         UIViewRoot root;
+        UIViewRoot previousRoot;
         String viewId;
         String newViewId;
+        boolean isNotSameRoot;
+        int loops = 0;
+        int maxLoops = 15;
         
         if (facesContext.getViewRoot() == null)
         {
@@ -62,6 +67,7 @@ class RenderResponseExecutor extends Pha
             do
             {
                 root = facesContext.getViewRoot();
+                previousRoot = root;
                 viewId = root.getViewId();
                 
                 ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(
@@ -81,12 +87,31 @@ class RenderResponseExecutor extends Pha
                 {
                     return false;
                 }
+
+                root = facesContext.getViewRoot();
+                
+                newViewId = root.getViewId();
                 
-                newViewId = facesContext.getViewRoot().getViewId();
+                isNotSameRoot = !( (newViewId == null ? newViewId == viewId : newViewId.equals(viewId) ) && 
+                        previousRoot.equals(root) ); 
+                
+                loops++;
             }
             while ((newViewId == null && viewId != null) 
-                    || (newViewId != null && !newViewId.equals(viewId)));
+                    || (newViewId != null && (!newViewId.equals(viewId) || isNotSameRoot ) ) && loops < maxLoops);
             
+            if (loops == maxLoops)
+            {
+                // PreRenderView reach maxLoops - probably a infinitive recursion:
+                boolean production = facesContext.isProjectStage(ProjectStage.Production);
+                Level level = production ? Level.FINE : Level.WARNING;
+                if (log.isLoggable(level))
+                {
+                    log.log(level, "Cicle over buildView-PreRenderViewEvent on RENDER_RESPONSE phase reaches maximal limit, please check " +
+                            "listeners for infinite recursion.");
+                }
+            }
+
             viewHandler.renderView(facesContext, root);
             
             // log all unhandled FacesMessages, don't swallow them