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/09/23 19:46:55 UTC

svn commit: r1174913 - in /myfaces/core/branches/2.0.x/impl/src: main/java/org/apache/myfaces/application/ test/java/org/apache/myfaces/application/ test/resources/org/apache/myfaces/application/

Author: lu4242
Date: Fri Sep 23 17:46:55 2011
New Revision: 1174913

URL: http://svn.apache.org/viewvc?rev=1174913&view=rev
Log:
MYFACES-3324 Conditional navigation match has priority over same case without conditional navigation

Added:
    myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/application/simple-if-rules-config-2.xml
Modified:
    myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
    myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java

Modified: myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java?rev=1174913&r1=1174912&r2=1174913&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java Fri Sep 23 17:46:55 2011
@@ -38,7 +38,6 @@ import javax.faces.application.Navigatio
 import javax.faces.application.ProjectStage;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewParameter;
 import javax.faces.component.UIViewRoot;
 import javax.faces.component.visit.VisitCallback;
 import javax.faces.component.visit.VisitContext;
@@ -449,9 +448,13 @@ public class NavigationHandlerImpl
     {
         NavigationCase noConditionCase = null;
         NavigationCase firstCase = null;
+        NavigationCase firstCaseIf = null;
         NavigationCase secondCase = null;
+        NavigationCase secondCaseIf = null;
         NavigationCase thirdCase = null;
+        NavigationCase thirdCaseIf = null;
         NavigationCase fourthCase = null;
+        NavigationCase fourthCaseIf = null;
                         
         for (NavigationCase caze : casesList)
         {
@@ -487,7 +490,7 @@ public class NavigationHandlerImpl
                         {
                             if (ifMatches)
                             {
-                                firstCase = caze;
+                                firstCaseIf = caze;
                                 //return caze;
                             }
 
@@ -511,7 +514,7 @@ public class NavigationHandlerImpl
                         {
                             if (ifMatches)
                             {
-                                thirdCase = caze;
+                                thirdCaseIf = caze;
                                 //return caze;
                             }
                             
@@ -543,7 +546,7 @@ public class NavigationHandlerImpl
                         {
                             if (ifMatches)
                             {
-                                secondCase = caze;
+                                secondCaseIf = caze;
                                 //return caze;
                             }
                             
@@ -567,7 +570,7 @@ public class NavigationHandlerImpl
                 {
                     if (ifMatches)
                     {
-                        fourthCase = caze;
+                        fourthCaseIf = caze;
                         //return caze;
                     }
                     
@@ -582,18 +585,34 @@ public class NavigationHandlerImpl
             }
         }
         
-        if (firstCase != null)
+        if (firstCaseIf != null)
+        {
+            return firstCaseIf;
+        }
+        else if (firstCase != null)
         {
             return firstCase;
         }
+        else if (secondCaseIf != null)
+        {
+            return secondCaseIf;
+        }
         else if (secondCase != null)
         {
             return secondCase;
         }
+        else if (thirdCaseIf != null)
+        {
+            return thirdCaseIf;
+        }
         else if (thirdCase != null)
         {
             return thirdCase;
         }
+        else if (fourthCaseIf != null)
+        {
+            return fourthCaseIf;
+        }
         else if (fourthCase != null)
         {
             return fourthCase;

Modified: myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java?rev=1174913&r1=1174912&r2=1174913&view=diff
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java (original)
+++ myfaces/core/branches/2.0.x/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java Fri Sep 23 17:46:55 2011
@@ -277,6 +277,22 @@ public class NavigationHandlerImplTest e
     }
     
     @Test
+    public void testGetSimpleIfPreferMathRule() throws Exception
+    {
+        loadTextFacesConfig("simple-if-rules-config-2.xml");
+
+        externalContext.getRequestMap().put("test", new TestBean());
+        
+        facesContext.getViewRoot().setViewId("/a.jsp");
+        
+        NavigationHandlerImpl nh = new NavigationHandlerImpl();
+
+        NavigationCase nc = nh.getNavigationCase(facesContext, null, "go");
+
+        Assert.assertEquals("/b.jsp", nc.getToViewId(facesContext));
+    }
+
+    @Test
     public void testGetSimpleNotIfExactMatchRule() throws Exception
     {
         loadTextFacesConfig("simple-if-rules-config.xml");

Added: myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/application/simple-if-rules-config-2.xml
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/application/simple-if-rules-config-2.xml?rev=1174913&view=auto
==============================================================================
--- myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/application/simple-if-rules-config-2.xml (added)
+++ myfaces/core/branches/2.0.x/impl/src/test/resources/org/apache/myfaces/application/simple-if-rules-config-2.xml Fri Sep 23 17:46:55 2011
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<!--
+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.
+-->
+
+<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>
+    <from-view-id>/a.jsp</from-view-id>
+    <navigation-case>
+        <from-outcome>go</from-outcome>
+        <if>#{test.true}</if>
+        <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-outcome>go</from-outcome>
+        <to-view-id>/c.jsp</to-view-id>
+    </navigation-case>
+  </navigation-rule>
+</faces-config>