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 2013/05/28 06:22:14 UTC

svn commit: r1486734 - in /myfaces/core/branches/2.1.x: impl/src/main/java/org/apache/myfaces/application/ impl/src/main/java/org/apache/myfaces/application/jsp/ shared/src/main/java/org/apache/myfaces/shared/application/

Author: lu4242
Date: Tue May 28 04:22:14 2013
New Revision: 1486734

URL: http://svn.apache.org/r1486734
Log:
MYFACES-3726 root context induces wrong urls

Modified:
    myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
    myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java
    myfaces/core/branches/2.1.x/shared/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java

Modified: myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java?rev=1486734&r1=1486733&r2=1486734&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java (original)
+++ myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/ViewHandlerImpl.java Tue May 28 04:22:14 2013
@@ -262,9 +262,22 @@ public class ViewHandlerImpl extends Vie
     {
         if (path.length() > 0 && path.charAt(0) == '/')
         {
-            return facesContext.getExternalContext().getRequestContextPath() + path;
+            String contextPath = facesContext.getExternalContext().getRequestContextPath();
+            if (contextPath == null)
+            {
+                return path;
+            }
+            else if (contextPath.length() == 1 && contextPath.charAt(0) == '/')
+            {
+                // If the context path is root, it is not necessary to append it, otherwise
+                // and extra '/' will be set.
+                return path;
+            }
+            else
+            {
+                return  contextPath + path;
+            }
         }
-
         return path;
 
     }

Modified: myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java?rev=1486734&r1=1486733&r2=1486734&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java (original)
+++ myfaces/core/branches/2.1.x/impl/src/main/java/org/apache/myfaces/application/jsp/JspViewHandlerImpl.java Tue May 28 04:22:14 2013
@@ -298,7 +298,21 @@ public class JspViewHandlerImpl extends 
     {
         if (path.length() > 0 && path.charAt(0) == '/')
         {
-            return facesContext.getExternalContext().getRequestContextPath() + path;
+            String contextPath = facesContext.getExternalContext().getRequestContextPath();
+            if (contextPath == null)
+            {
+                return path;
+            }
+            else if (contextPath.length() == 1 && contextPath.charAt(0) == '/')
+            {
+                // If the context path is root, it is not necessary to append it, otherwise
+                // and extra '/' will be set.
+                return path;
+            }
+            else
+            {
+                return  contextPath + path;
+            }
         }
 
         return path;

Modified: myfaces/core/branches/2.1.x/shared/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.1.x/shared/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java?rev=1486734&r1=1486733&r2=1486734&view=diff
==============================================================================
--- myfaces/core/branches/2.1.x/shared/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java (original)
+++ myfaces/core/branches/2.1.x/shared/src/main/java/org/apache/myfaces/shared/application/DefaultViewHandlerSupport.java Tue May 28 04:22:14 2013
@@ -198,7 +198,12 @@ public class DefaultViewHandlerSupport i
         String contextPath = externalContext.getRequestContextPath();
         //StringBuilder builder = new StringBuilder(contextPath);
         StringBuilder builder = SharedStringBuilder.get(context, VIEW_HANDLER_SUPPORT_SB);
-        builder.append(contextPath);
+        // If the context path is root, it is not necessary to append it, otherwise
+        // and extra '/' will be set.
+        if (contextPath != null && !(contextPath.length() == 1 && contextPath.charAt(0) == '/') )
+        {
+            builder.append(contextPath);
+        }
         if (mapping != null)
         {
             if (mapping.isExtensionMapping())