http://java.net/jira/browse/JAVASERVERFACES-1567
http://java.net/jira/browse/JAVASERVERFACES-1567 Consult ResourceResolver, if non-default, for implicitNavigation
SECTION: Modified Files
----------------------------
M jsf-ri/src/main/java/com/sun/faces/application/NavigationHandlerImpl.java
- the core of the change. In findImplicitMatch(), before consulting the
ViewHandler, if the ResourceResolver is not the default
ResourceResolver, consult it to see if the view exists. If it does,
use it, if not, do the previous behavior of consulting the
ViewHandler.
M jsf-ri/systest-per-webapp/replace-application/src/java/com/sun/faces/systest/ReplaceApplicationTestCase.java
M jsf-ri/systest-per-webapp/replace-application/web/WEB-INF/faces-config.xml
M jsf-ri/systest-per-webapp/replace-application/web/WEB-INF/web.xml
A jsf-ri/systest-per-webapp/replace-application/src/java/com/sun/faces/systest/ResourceResolverImpl.java
A jsf-ri/systest-per-webapp/replace-application/web/page1.xhtml
A jsf-ri/systest-per-webapp/replace-application/web/page2.xhtml
- Automated test content.
SECTION: Diffs
----------------------------
Index: jsf-ri/src/main/java/com/sun/faces/application/NavigationHandlerImpl.java
===================================================================
--- jsf-ri/src/main/java/com/sun/faces/application/NavigationHandlerImpl.java (revision 8735)
+++ jsf-ri/src/main/java/com/sun/faces/application/NavigationHandlerImpl.java (working copy)
@@ -40,6 +40,7 @@
package com.sun.faces.application;
+import com.sun.faces.facelets.impl.DefaultResourceResolver;
import javax.faces.FacesException;
import javax.faces.application.NavigationCase;
import javax.faces.application.ViewHandler;
@@ -57,8 +58,10 @@
import com.sun.faces.util.MessageUtils;
import com.sun.faces.util.Util;
import com.sun.faces.util.FacesLogger;
+import java.net.URL;
import javax.faces.application.ConfigurableNavigationHandler;
import javax.faces.application.FacesMessage;
+import javax.faces.view.facelets.ResourceResolver;
/**
* <p><strong>NavigationHandlerImpl</strong> is the class that implements
@@ -541,9 +544,32 @@
}
}
- ViewHandler viewHandler = Util.getViewHandler(context);
- viewIdToTest = viewHandler.deriveViewId(context, viewIdToTest);
+ ApplicationAssociate ass = ApplicationAssociate.getCurrentInstance();
+ ResourceResolver resolver = ass.getFaceletFactory().getResourceResolver();
+ boolean consultViewHandler = true;
+ if (!(resolver instanceof DefaultResourceResolver)) {
+ URL url = resolver.resolveUrl(viewIdToTest);
+ if (null != url) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.log(Level.FINE, "ResourceResolver.resolveUrl({0}) returned {1}",
+ new Object[]{viewIdToTest, url.toExternalForm()});
+ }
+ // derive the viewId from the URL
+ String contextPath = context.getExternalContext().getRequestContextPath();
+ int contextPathLen = contextPath.length();
+ viewIdToTest = url.toExternalForm();
+ // remove the url up to and including the context path.
+ int i = viewIdToTest.indexOf(contextPath);
+ viewIdToTest = viewIdToTest.substring(i + contextPathLen);
+ consultViewHandler = false;
+ }
+ }
+ if (consultViewHandler) {
+ ViewHandler viewHandler = Util.getViewHandler(context);
+ viewIdToTest = viewHandler.deriveViewId(context, viewIdToTest);
+ }
+
if (null != viewIdToTest) {
CaseStruct caseStruct = new CaseStruct();
caseStruct.viewId = viewIdToTest;
Index: jsf-ri/systest-per-webapp/replace-application/src/java/com/sun/faces/systest/ReplaceApplicationTestCase.java
===================================================================
--- jsf-ri/systest-per-webapp/replace-application/src/java/com/sun/faces/systest/ReplaceApplicationTestCase.java (revision 8735)
+++ jsf-ri/systest-per-webapp/replace-application/src/java/com/sun/faces/systest/ReplaceApplicationTestCase.java (working copy)
@@ -41,25 +41,13 @@
package com.sun.faces.systest;
-import com.gargoylesoftware.htmlunit.WebClient;
-import com.gargoylesoftware.htmlunit.html.HtmlBody;
-import com.gargoylesoftware.htmlunit.html.HtmlElement;
-import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
-import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
-import com.gargoylesoftware.htmlunit.html.HtmlSelect;
-import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
import com.sun.faces.htmlunit.AbstractTestCase;
import junit.framework.Test;
-import junit.framework.TestCase;
import junit.framework.TestSuite;
-import java.util.List;
-import java.util.Random;
-import java.util.ResourceBundle;
-import javax.faces.component.NamingContainer;
/**
@@ -133,4 +121,12 @@
assertTrue(-1 != page.asText().indexOf("com.sun.faces.systest.NewApplication"));
}
+ public void testResourceResolverImplicitNavigation() throws Exception {
+ HtmlPage page = getPage("/faces/page1.xhtml");
+ HtmlSubmitInput button = (HtmlSubmitInput) page.getElementById("next");
+ page = button.click();
+ assertTrue(page.asText().contains("Using ResourceResolver for implicit navigation"));
+ }
+
+
}
Index: jsf-ri/systest-per-webapp/replace-application/src/java/com/sun/faces/systest/ResourceResolverImpl.java
===================================================================
--- jsf-ri/systest-per-webapp/replace-application/src/java/com/sun/faces/systest/ResourceResolverImpl.java (revision 0)
+++ jsf-ri/systest-per-webapp/replace-application/src/java/com/sun/faces/systest/ResourceResolverImpl.java (revision 0)
@@ -0,0 +1,74 @@
+
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License"). You
+ * may not use this file except in compliance with the License. You can
+ * obtain a copy of the License at
+ *
https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ * or packager/legal/LICENSE.txt. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * Oracle designates this particular file as subject to the "Classpath"
+ * exception as provided by Oracle in the GPL Version 2 section of the License
+ * file that accompanied this code.
+ *
+ * Modifications:
+ * If applicable, add the following below the License Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyright [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or GPL
+ * Version 2] license." If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above. However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package com.sun.faces.systest;
+
+import java.net.URL;
+import java.util.Map;
+import javax.faces.context.FacesContext;
+import javax.faces.view.facelets.ResourceResolver;
+
+
+public class ResourceResolverImpl extends ResourceResolver {
+
+ private ResourceResolver parent;
+
+ public ResourceResolverImpl(ResourceResolver parent) {
+ this.parent = parent;
+ }
+
+
+ @Override
+ public URL resolveUrl(String string) {
+ Map<String, Object> requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+ URL result = null;
+ if (string.contains("nonexistentViewId")) {
+ string = string.replace("nonexistentViewId", "page2");
+ requestMap.put("message", "Using ResourceResolver for implicit navigation");
+ }
+ result = parent.resolveUrl(string);
+ return result;
+
+ }
+
+
+
+}
Index: jsf-ri/systest-per-webapp/replace-application/web/WEB-INF/faces-config.xml
===================================================================
--- jsf-ri/systest-per-webapp/replace-application/web/WEB-INF/faces-config.xml (revision 8735)
+++ jsf-ri/systest-per-webapp/replace-application/web/WEB-INF/faces-config.xml (working copy)
@@ -43,8 +43,8 @@
<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_1_2.xsd"
- version="1.2">
+ xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
+ version="2.1">
<application>
<view-handler>com.sun.faces.systest.NewViewHandler</view-handler>
Index: jsf-ri/systest-per-webapp/replace-application/web/WEB-INF/web.xml
===================================================================
--- jsf-ri/systest-per-webapp/replace-application/web/WEB-INF/web.xml (revision 8735)
+++ jsf-ri/systest-per-webapp/replace-application/web/WEB-INF/web.xml (working copy)
@@ -43,8 +43,8 @@
<web-app 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 web-app_2_5.xsd"
- version="2.5">
+ xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee web-app_3_0.xsd"
+ version="3.0">
<description>
JSF Systests
@@ -70,6 +70,11 @@
<param-value>client</param-value>
</context-param>
+ <context-param>
+ <param-name>javax.faces.FACELETS_RESOURCE_RESOLVER</param-name>
+ <param-value>com.sun.faces.systest.ResourceResolverImpl</param-value>
+ </context-param>
+
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
Index: jsf-ri/systest-per-webapp/replace-application/web/page1.xhtml
===================================================================
--- jsf-ri/systest-per-webapp/replace-application/web/page1.xhtml (revision 0)
+++ jsf-ri/systest-per-webapp/replace-application/web/page1.xhtml (revision 0)
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<!--
+
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 2 only ("GPL") or the Common Development
+ and Distribution License("CDDL") (collectively, the "License"). You
+ may not use this file except in compliance with the License. You can
+ obtain a copy of the License at
+
https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ or packager/legal/LICENSE.txt. See the License for the specific
+ language governing permissions and limitations under the License.
+
+ When distributing the software, include this License Header Notice in each
+ file and include the License file at packager/legal/LICENSE.txt.
+
+ GPL Classpath Exception:
+ Oracle designates this particular file as subject to the "Classpath"
+ exception as provided by Oracle in the GPL Version 2 section of the License
+ file that accompanied this code.
+
+ Modifications:
+ If applicable, add the following below the License Header, with the fields
+ enclosed by brackets [] replaced by your own identifying information:
+ "Portions Copyright [year] [name of copyright owner]"
+
+ Contributor(s):
+ If you wish your version of this file to be governed by only the CDDL or
+ only the GPL Version 2, indicate your decision by adding "[Contributor]
+ elects to include this software in this distribution under the [CDDL or GPL
+ Version 2] license." If you don't indicate a single choice of license, a
+ recipient has the option to distribute your version of this file under
+ either the CDDL, the GPL Version 2 or to extend the choice of license to
+ its licensees as provided above. However, if you add GPL Version 2 code
+ and therefore, elected the GPL Version 2 license, then the option applies
+ only if the new code is made subject to such option by the copyright
+ holder.
+
+-->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="
http://www.w3.org/1999/xhtml"
+ xmlns:h="
http://java.sun.com/jsf/html">
+<h:head>
+ <title>Page 1</title>
+</h:head>
+<h:body bgcolor="white">
+
+<h2>Page 1</h2>
+
+
+<h:form prependId="false">
+ <h:commandButton id="next" value="next" action="nonexistentViewId" />
+</h:form>
+
+</h:body>
+</html>
Index: jsf-ri/systest-per-webapp/replace-application/web/page2.xhtml
===================================================================
--- jsf-ri/systest-per-webapp/replace-application/web/page2.xhtml (revision 0)
+++ jsf-ri/systest-per-webapp/replace-application/web/page2.xhtml (revision 0)
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
+<!--
+
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+
+ Copyright (c) 2009-2010 Oracle and/or its affiliates. All rights reserved.
+
+ The contents of this file are subject to the terms of either the GNU
+ General Public License Version 2 only ("GPL") or the Common Development
+ and Distribution License("CDDL") (collectively, the "License"). You
+ may not use this file except in compliance with the License. You can
+ obtain a copy of the License at
+
https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ or packager/legal/LICENSE.txt. See the License for the specific
+ language governing permissions and limitations under the License.
+
+ When distributing the software, include this License Header Notice in each
+ file and include the License file at packager/legal/LICENSE.txt.
+
+ GPL Classpath Exception:
+ Oracle designates this particular file as subject to the "Classpath"
+ exception as provided by Oracle in the GPL Version 2 section of the License
+ file that accompanied this code.
+
+ Modifications:
+ If applicable, add the following below the License Header, with the fields
+ enclosed by brackets [] replaced by your own identifying information:
+ "Portions Copyright [year] [name of copyright owner]"
+
+ Contributor(s):
+ If you wish your version of this file to be governed by only the CDDL or
+ only the GPL Version 2, indicate your decision by adding "[Contributor]
+ elects to include this software in this distribution under the [CDDL or GPL
+ Version 2] license." If you don't indicate a single choice of license, a
+ recipient has the option to distribute your version of this file under
+ either the CDDL, the GPL Version 2 or to extend the choice of license to
+ its licensees as provided above. However, if you add GPL Version 2 code
+ and therefore, elected the GPL Version 2 license, then the option applies
+ only if the new code is made subject to such option by the copyright
+ holder.
+
+-->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="
http://www.w3.org/1999/xhtml"
+ xmlns:h="
http://java.sun.com/jsf/html">
+<h:head>
+ <title>Page 2</title>
+</h:head>
+<h:body bgcolor="white">
+
+<h2>Page 2</h2>
+
+<p>#{requestScope.message}</p>
+
+<h:form prependId="false">
+ <h:commandButton id="prev" value="prev" action="page1" />
+</h:form>
+
+</h:body>
+</html>
SECTION: New Files
----------------------------
SEE ATTACHMENTS
--
| ed.burns_at_sun.com | office: +1 407 458 0017
| homepage: | http://ridingthecrest.com/