myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From martink...@apache.org
Subject svn commit: r1099449 - in /myfaces/core/trunk/impl/src: main/java/org/apache/myfaces/application/NavigationHandlerImpl.java test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java
Date Wed, 04 May 2011 13:52:56 GMT
Author: martinkoci
Date: Wed May  4 13:52:55 2011
New Revision: 1099449

URL: http://svn.apache.org/viewvc?rev=1099449&view=rev
Log:
MYFACES-3101 NavigationHandlerImpl throws NullpointerException if view is expired

Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
    myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java?rev=1099449&r1=1099448&r2=1099449&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
(original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
Wed May  4 13:52:55 2011
@@ -114,9 +114,10 @@ public class NavigationHandlerImpl
                 // PartialViewContext.setRenderAll(true)...". The effect is that ajax requests
                 // are included on navigation.
                 PartialViewContext partialViewContext = facesContext.getPartialViewContext();
+                String viewId = facesContext.getViewRoot() != null ? facesContext.getViewRoot().getViewId()
: null;
                 if ( partialViewContext.isPartialRequest() && 
                      !partialViewContext.isRenderAll() && 
-                     !facesContext.getViewRoot().getViewId().equals(toViewId))
+                     !toViewId.equals(viewId))
                 {
                     partialViewContext.setRenderAll(true);
                 }
@@ -143,9 +144,10 @@ public class NavigationHandlerImpl
                 // PartialViewContext.setRenderAll(true)...". The effect is that ajax requests
                 // are included on navigation.
                 PartialViewContext partialViewContext = facesContext.getPartialViewContext();
+                String viewId = facesContext.getViewRoot() != null ? facesContext.getViewRoot().getViewId()
: null;
                 if ( partialViewContext.isPartialRequest() && 
                      !partialViewContext.isRenderAll() && 
-                     !facesContext.getViewRoot().getViewId().equals(newViewId))
+                     !newViewId.equals(viewId))
                 {
                     partialViewContext.setRenderAll(true);
                 }
@@ -200,15 +202,20 @@ public class NavigationHandlerImpl
      */
     public NavigationCase getNavigationCase(FacesContext facesContext, String fromAction,
String outcome)
     {
-        String viewId = facesContext.getViewRoot().getViewId();
+        String viewId = facesContext.getViewRoot() != null ? facesContext.getViewRoot().getViewId()
: null;
+        
         Map<String, Set<NavigationCase>> casesMap = getNavigationCases();
         NavigationCase navigationCase = null;
-
-        Set<? extends NavigationCase> casesSet = casesMap.get(viewId);
-        if (casesSet != null)
+        
+        Set<? extends NavigationCase> casesSet;
+        if (viewId != null)
         {
-            // Exact match?
-            navigationCase = calcMatchingNavigationCase(facesContext, casesSet, fromAction,
outcome);
+            casesSet = casesMap.get(viewId);
+            if (casesSet != null)
+            {
+                // Exact match?
+                navigationCase = calcMatchingNavigationCase(facesContext, casesSet, fromAction,
outcome);
+            }
         }
 
         if (navigationCase == null)
@@ -273,7 +280,7 @@ public class NavigationHandlerImpl
         boolean isRedirect = false;
         String queryString = null;
         NavigationCase result = null;
-        String viewId = facesContext.getViewRoot().getViewId();
+        String viewId = facesContext.getViewRoot() != null ? facesContext.getViewRoot().getViewId()
: null;
         String viewIdToTest = outcome;
         
         // If viewIdToTest contains a query string, remove it and set queryString with that
value.
@@ -300,7 +307,7 @@ public class NavigationHandlerImpl
         
         // If viewIdToTest does not have a "file extension", use the one from the current
viewId.
         index = viewIdToTest.indexOf (".");
-        if (index == -1)
+        if (index == -1 && viewId != null)
         {
             index = viewId.lastIndexOf(".");
             
@@ -313,7 +320,7 @@ public class NavigationHandlerImpl
         // If viewIdToTest does not start with "/", look for the last "/" in viewId.  If
not found, simply prepend "/".
         // Otherwise, prepend everything before and including the last "/" in viewId.
         
-        if (!viewIdToTest.startsWith ("/"))
+        if (!viewIdToTest.startsWith ("/") && viewId != null)
         {
             index = viewId.lastIndexOf ("/");
             

Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java?rev=1099449&r1=1099448&r2=1099449&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java
(original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java
Wed May  4 13:52:55 2011
@@ -18,6 +18,9 @@
  */
 package org.apache.myfaces.application;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -565,4 +568,37 @@ public class NavigationHandlerImplTest e
         Assert.assertTrue("redirect=true in the query String must "
                 + "set redirect to true.", navigationCase.isRedirect());
     }
+    
+    /**
+     * Test for MYFACES-3101
+     */
+    @Test
+    public void testHandleViewExpiredExpcetion() throws Exception {
+        NavigationHandlerImpl underTest = new NavigationHandlerImpl();
+        // simulate no available ViewRoot (in case of VEE)
+        facesContext.setViewRoot(null);
+        // test is based on:
+        // http://www.nfjsone.com/blog/ed_burns/2009/09/dealing_gracefully_with_viewexpiredexception_in_jsf2
+        underTest.handleNavigation(facesContext, null, "viewExpired");
+
+        assertNotNull(facesContext.getViewRoot());
+        assertEquals("viewExpired", facesContext.getViewRoot().getViewId());
+        
+    }
+    
+    /**
+     * Test for MYFACES-3101 - partial request (without redirect)
+     */
+    @Test
+    public void testHandleViewExpiredExpcetionForPartial() throws Exception {
+        NavigationHandlerImpl underTest = new NavigationHandlerImpl();
+        // simulate no available ViewRoot (in case of VEE)
+        facesContext.setViewRoot(null);
+        facesContext.getPartialViewContext().setPartialRequest(true);
+        
+        underTest.handleNavigation(facesContext, null, "/viewExpired.xhtml");
+        
+        assertNotNull(facesContext.getViewRoot());
+        assertEquals("/viewExpired.xhtml", facesContext.getViewRoot().getViewId());
+    }
 }



Mime
View raw message