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 2010/04/26 21:33:41 UTC

svn commit: r938202 - in /myfaces/core/trunk/impl/src: main/java/org/apache/myfaces/application/ test/java/org/apache/myfaces/application/ test/resources/org/apache/myfaces/application/

Author: lu4242
Date: Mon Apr 26 19:33:41 2010
New Revision: 938202

URL: http://svn.apache.org/viewvc?rev=938202&view=rev
Log:
MYFACES-2678 Problems with navigation case ordering

Added:
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/application/simple-action-outcome-precedence-2-config.xml
    myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/application/simple-action-outcome-precedence-config.xml
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=938202&r1=938201&r2=938202&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 Mon Apr 26 19:33:41 2010
@@ -345,6 +345,10 @@ public class NavigationHandlerImpl
                                                       String outcome)
     {
         NavigationCase noConditionCase = null;
+        NavigationCase firstCase = null;
+        NavigationCase secondCase = null;
+        NavigationCase thirdCase = null;
+        NavigationCase fourthCase = null;
                         
         for (NavigationCase caze : casesList)
         {
@@ -380,14 +384,16 @@ public class NavigationHandlerImpl
                         {
                             if (ifMatches)
                             {
-                                return caze;
+                                firstCase = caze;
+                                //return caze;
                             }
 
                             continue;
                         }
                         else
                         {
-                            return caze;
+                            firstCase = caze;
+                            //return caze;
                         }
                     }
                 }
@@ -402,7 +408,8 @@ public class NavigationHandlerImpl
                         {
                             if (ifMatches)
                             {
-                                return caze;
+                                thirdCase = caze;
+                                //return caze;
                             }
                             
                             continue;
@@ -411,7 +418,8 @@ public class NavigationHandlerImpl
                         {
                             if (outcome != null)
                             {
-                                return caze;
+                                thirdCase = caze;
+                                //return caze;
                             }
                             
                             continue;
@@ -432,14 +440,16 @@ public class NavigationHandlerImpl
                         {
                             if (ifMatches)
                             {
-                                return caze;
+                                secondCase = caze;
+                                //return caze;
                             }
                             
                             continue;
                         }
                         else
                         {
-                            return caze;
+                            secondCase = caze;
+                            //return caze;
                         }
                     }
                 }
@@ -454,7 +464,8 @@ public class NavigationHandlerImpl
                 {
                     if (ifMatches)
                     {
-                        return caze;
+                        fourthCase = caze;
+                        //return caze;
                     }
                     
                     continue;
@@ -463,10 +474,28 @@ public class NavigationHandlerImpl
 
             if ((cazeIf != null) && ifMatches)
             {
-                return caze;
+                fourthCase = caze;
+                //return caze;
             }
         }
         
+        if (firstCase != null)
+        {
+            return firstCase;
+        }
+        else if (secondCase != null)
+        {
+            return secondCase;
+        }
+        else if (thirdCase != null)
+        {
+            return thirdCase;
+        }
+        else if (fourthCase != null)
+        {
+            return fourthCase;
+        }
+        
         return noConditionCase;
     }
 

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=938202&r1=938201&r2=938202&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 Mon Apr 26 19:33:41 2010
@@ -1,6 +1,13 @@
 package org.apache.myfaces.application;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import javax.faces.FactoryFinder;
 import javax.faces.application.ApplicationFactory;
@@ -308,4 +315,158 @@ public class NavigationHandlerImplTest e
 
         assertNull(nc);
     }
+    
+    public void testActionOutcomePrecendeceMachRule() throws Exception
+    {
+        loadTextFacesConfig("simple-action-outcome-precedence-config.xml");
+
+        for (int i = 0; i < 2; i++)
+        {
+            final int j = i;
+            facesContext.getViewRoot().setViewId("/a.jsp");
+            
+            NavigationHandlerImpl nh = new NavigationHandlerImpl(){
+    
+                @Override
+                public Map<String, Set<NavigationCase>> getNavigationCases()
+                {
+                    // We have two conditions, this code is for rotate the ordering so we
+                    // test all possible outputs
+                    Map<String, Set<NavigationCase>> map = super.getNavigationCases();
+                    Map<String, Set<NavigationCase>> map2 = new HashMap<String, Set<NavigationCase>>();
+                    
+                    for (Map.Entry<String, Set<NavigationCase>> entry : map.entrySet())
+                    {
+                        LinkedHashSet<NavigationCase> set = new LinkedHashSet<NavigationCase>();
+                        List<NavigationCase> list = new ArrayList<NavigationCase>();
+                        list.addAll(entry.getValue());
+                        Collections.rotate(list, j);
+                        set.addAll(list);
+                        map2.put(entry.getKey(), set);
+                    }
+                    return map2; 
+                }
+            };
+    
+            NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", "go");
+    
+            assertEquals("/b.jsp", nc.getToViewId(facesContext));
+        }
+    }
+    
+    public void testActionOutcomePrecendeceAlternateOutcomeMachRule() throws Exception
+    {
+        loadTextFacesConfig("simple-action-outcome-precedence-config.xml");
+
+        for (int i = 0; i < 2; i++)
+        {
+            final int j = i;
+            facesContext.getViewRoot().setViewId("/a.jsp");
+            
+            NavigationHandlerImpl nh = new NavigationHandlerImpl(){
+    
+                @Override
+                public Map<String, Set<NavigationCase>> getNavigationCases()
+                {
+                    // We have two conditions, this code is for rotate the ordering so we
+                    // test all possible outputs
+                    Map<String, Set<NavigationCase>> map = super.getNavigationCases();
+                    Map<String, Set<NavigationCase>> map2 = new HashMap<String, Set<NavigationCase>>();
+                    
+                    for (Map.Entry<String, Set<NavigationCase>> entry : map.entrySet())
+                    {
+                        LinkedHashSet<NavigationCase> set = new LinkedHashSet<NavigationCase>();
+                        List<NavigationCase> list = new ArrayList<NavigationCase>();
+                        list.addAll(entry.getValue());
+                        Collections.rotate(list, j);
+                        set.addAll(list);
+                        map2.put(entry.getKey(), set);
+                    }
+                    return map2; 
+                }
+            };
+    
+            NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", "nogo");
+    
+            assertEquals("/c.jsp", nc.getToViewId(facesContext));
+        }
+    }
+
+    public void testActionOutcomePrecendeceNoOutcomeMachRule() throws Exception
+    {
+        loadTextFacesConfig("simple-action-outcome-precedence-config.xml");
+
+        for (int i = 0; i < 2; i++)
+        {
+            final int j = i;
+            facesContext.getViewRoot().setViewId("/a.jsp");
+            
+            NavigationHandlerImpl nh = new NavigationHandlerImpl(){
+    
+                @Override
+                public Map<String, Set<NavigationCase>> getNavigationCases()
+                {
+                    // We have two conditions, this code is for rotate the ordering so we
+                    // test all possible outputs
+                    Map<String, Set<NavigationCase>> map = super.getNavigationCases();
+                    Map<String, Set<NavigationCase>> map2 = new HashMap<String, Set<NavigationCase>>();
+                    
+                    for (Map.Entry<String, Set<NavigationCase>> entry : map.entrySet())
+                    {
+                        LinkedHashSet<NavigationCase> set = new LinkedHashSet<NavigationCase>();
+                        List<NavigationCase> list = new ArrayList<NavigationCase>();
+                        list.addAll(entry.getValue());
+                        Collections.rotate(list, j);
+                        set.addAll(list);
+                        map2.put(entry.getKey(), set);
+                    }
+                    return map2; 
+                }
+            };
+    
+            NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", null);
+    
+            //If the <if> element is absent, only match a non-null outcome
+            assertNull(nc);
+        }
+    }
+
+    
+    public void testActionOutcomePrecendece2MachRule() throws Exception
+    {
+        loadTextFacesConfig("simple-action-outcome-precedence-2-config.xml");
+
+        for (int i = 0; i < 2; i++)
+        {
+            final int j = i;
+            facesContext.getViewRoot().setViewId("/a.jsp");
+            
+            NavigationHandlerImpl nh = new NavigationHandlerImpl(){
+    
+                @Override
+                public Map<String, Set<NavigationCase>> getNavigationCases()
+                {
+                    // We have two conditions, this code is for rotate the ordering so we
+                    // test all possible outputs
+                    Map<String, Set<NavigationCase>> map = super.getNavigationCases();
+                    Map<String, Set<NavigationCase>> map2 = new HashMap<String, Set<NavigationCase>>();
+                    
+                    for (Map.Entry<String, Set<NavigationCase>> entry : map.entrySet())
+                    {
+                        LinkedHashSet<NavigationCase> set = new LinkedHashSet<NavigationCase>();
+                        List<NavigationCase> list = new ArrayList<NavigationCase>();
+                        list.addAll(entry.getValue());
+                        Collections.rotate(list, j);
+                        set.addAll(list);
+                        map2.put(entry.getKey(), set);
+                    }
+                    return map2; 
+                }
+            };
+    
+            NavigationCase nc = nh.getNavigationCase(facesContext, "#{rules.go}", "go");
+    
+            assertEquals("/b.jsp", nc.getToViewId(facesContext));
+        }
+    }
 }
\ No newline at end of file

Added: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/application/simple-action-outcome-precedence-2-config.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/application/simple-action-outcome-precedence-2-config.xml?rev=938202&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/application/simple-action-outcome-precedence-2-config.xml (added)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/application/simple-action-outcome-precedence-2-config.xml Mon Apr 26 19:33:41 2010
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+  version="2.0">
+  <!-- Single outcome takes precedence over action -->
+ <navigation-rule>
+  <from-view-id>/a.jsp</from-view-id>
+  <navigation-case>
+   <from-outcome>go</from-outcome>
+   <to-view-id>/b.jsp</to-view-id>
+  </navigation-case>
+ </navigation-rule>
+
+ <navigation-rule>
+  <from-view-id>/a.jsp</from-view-id>
+  <navigation-case>
+   <from-action>#{rules.go}</from-action>
+   <to-view-id>/c.jsp</to-view-id>
+  </navigation-case>
+ </navigation-rule> 
+</faces-config>

Added: myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/application/simple-action-outcome-precedence-config.xml
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/application/simple-action-outcome-precedence-config.xml?rev=938202&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/application/simple-action-outcome-precedence-config.xml (added)
+++ myfaces/core/trunk/impl/src/test/resources/org/apache/myfaces/application/simple-action-outcome-precedence-config.xml Mon Apr 26 19:33:41 2010
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
+  version="2.0">
+ <navigation-rule>
+  <!-- Single outcome and action takes precedence over action -->
+  <from-view-id>/a.jsp</from-view-id>
+  <navigation-case>
+   <from-action>#{rules.go}</from-action>
+   <from-outcome>go</from-outcome>
+   <to-view-id>/b.jsp</to-view-id>
+  </navigation-case>
+ </navigation-rule>
+
+ <navigation-rule>
+  <from-view-id>/a.jsp</from-view-id>
+  <navigation-case>
+   <from-action>#{rules.go}</from-action>
+   <to-view-id>/c.jsp</to-view-id>
+  </navigation-case>
+ </navigation-rule> 
+</faces-config>