Skip to content

Commit e8a9c34

Browse files
committed
Merge pull request ocpsoft#113 from andreiamariei/issue-109
Fixes Issue ocpsoft#109 - Context root is appended twice when using Navigate.to() class
2 parents 8fac96c + 47b5a7d commit e8a9c34

5 files changed

Lines changed: 84 additions & 1 deletion

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.ocpsoft.rewrite.prettyfaces.interaction;
2+
3+
import org.ocpsoft.rewrite.faces.navigate.Navigate;
4+
5+
import javax.enterprise.context.RequestScoped;
6+
import javax.inject.Named;
7+
8+
@Named("facesInteraction")
9+
@RequestScoped
10+
public class FacesNavigateInteractionBean
11+
{
12+
13+
public Navigate navigate()
14+
{
15+
return Navigate.to("/page.jsf");
16+
}
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.ocpsoft.rewrite.prettyfaces.interaction;
2+
3+
import com.gargoylesoftware.htmlunit.html.HtmlPage;
4+
import org.jboss.arquillian.container.test.api.Deployment;
5+
import org.jboss.arquillian.junit.Arquillian;
6+
import org.jboss.shrinkwrap.api.spec.WebArchive;
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
import org.ocpsoft.rewrite.prettyfaces.PrettyFacesTestBase;
10+
import org.ocpsoft.rewrite.test.RewriteTestBase;
11+
12+
import static org.junit.Assert.assertEquals;
13+
14+
@RunWith(Arquillian.class)
15+
public class FacesNavigateInteractionTest extends RewriteTestBase
16+
{
17+
@Deployment(testable = false)
18+
public static WebArchive createDeployment()
19+
{
20+
return PrettyFacesTestBase.getDeployment()
21+
.addClass(FacesNavigateInteractionBean.class)
22+
.addAsWebResource("interaction/faces-navigate-page.xhtml", "page.xhtml")
23+
.addAsWebInfResource("interaction/faces-navigate-pretty-config.xml", "pretty-config.xml");
24+
}
25+
26+
@Test
27+
public void testNavigate() throws Exception
28+
{
29+
HtmlPage firstPage = getWebClient("/page").getPage();
30+
HtmlPage secondPage = firstPage.getElementById("navigate").click();
31+
assertEquals(secondPage.getUrl().getPath(), getContextPath() + "/page");
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html xmlns="http://www.w3.org/1999/xhtml"
4+
xmlns:f="http://java.sun.com/jsf/core"
5+
xmlns:h="http://java.sun.com/jsf/html"
6+
xmlns:pretty="http://ocpsoft.com/prettyfaces"
7+
xmlns:ui="http://java.sun.com/jsf/facelets">
8+
9+
<head>
10+
<title>Navigate Test</title>
11+
</head>
12+
13+
<body>
14+
15+
<h1>Navigate Test</h1>
16+
17+
<h:form prependId="false">
18+
<h:commandLink id="navigate" action="#{facesInteraction.navigate}" value="navigate" />
19+
</h:form>
20+
21+
</body>
22+
</html>
23+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<pretty-config xmlns="http://ocpsoft.com/prettyfaces/3.3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://ocpsoft.com/prettyfaces/3.3.2 http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.2.xsd">
3+
4+
<!-- Simple URL mapping -->
5+
<url-mapping>
6+
<pattern value="/page"></pattern>
7+
<view-id>/page.jsf</view-id>
8+
</url-mapping>
9+
10+
</pretty-config>

‎integration-faces/src/main/java/org/ocpsoft/rewrite/faces/RewriteNavigationHandler.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ else if (outcome != null && outcome.startsWith(REDIRECT_PREFIX)) {
155155
private String prependContextPath(ExternalContext externalContext, String url)
156156
{
157157
String contextPath = externalContext.getRequestContextPath();
158-
if ("/".equals(contextPath)) {
158+
if ("/".equals(contextPath) || (url.startsWith(contextPath))) {
159159
return url;
160160
}
161161
return contextPath + url;

0 commit comments

Comments
 (0)