Skip to content

Commit 26212ab

Browse files
committed
Fixed bug that caused mappings to also match viewIds of other mappings (#128)
1 parent f2c2bc6 commit 26212ab

5 files changed

Lines changed: 106 additions & 1 deletion

File tree

‎CHANGELOG.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Bugfixes:
1414
* Fixed encoding for square brackets and less/greater than characters
1515
* Don't apply rewrite rule to requests forwarded by URL-mappings anymore
1616
* Fixed encoding/decoding of vertical bar (|) character
17+
* Fixed bug that caused mappings to also match viewIds of other mappings (#128)
1718

1819
------------------------------------
1920
VERSION 3.3.2

‎core/src/main/java/com/ocpsoft/pretty/PrettyFilter.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,19 @@ public void doFilter(final ServletRequest req, final ServletResponse resp, final
9191
else
9292
{
9393
URL url = context.getRequestURL();
94-
UrlMapping mapping = getConfig().getMappingForUrl(url);
94+
95+
/*
96+
* This code will be executed even for the requests already forwarded by PrettyFaces.
97+
* As some patterns may also match viewIds to which PrettyFaces forwards, we lookup
98+
* the matching URL mapping only if we are not already in a forward.
99+
* (Fix for #128)
100+
*/
101+
UrlMapping mapping = null;
102+
if (!isUrlMappingForward(req))
103+
{
104+
mapping = getConfig().getMappingForUrl(url);
105+
}
106+
95107
if (mapping != null)
96108
{
97109
context.setCurrentMapping(mapping);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.ocpsoft.pretty.faces.test.viewidmatch;
2+
3+
import javax.faces.bean.ManagedBean;
4+
import javax.faces.bean.RequestScoped;
5+
6+
import com.ocpsoft.pretty.faces.annotation.URLMapping;
7+
8+
@ManagedBean
9+
@RequestScoped
10+
// Please note that this pattern also matches the viewId
11+
@URLMapping(pattern = "/path/#{viewIdMatchBean.value}", viewId = "/path/viewidmatch.jsf")
12+
public class ViewIdMatchBean
13+
{
14+
15+
private String value;
16+
17+
public String getValue()
18+
{
19+
return value;
20+
}
21+
22+
public void setValue(String value)
23+
{
24+
this.value = value;
25+
}
26+
27+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.ocpsoft.pretty.faces.test.viewidmatch;
2+
3+
import static junit.framework.Assert.assertEquals;
4+
import static junit.framework.Assert.assertTrue;
5+
6+
import org.jboss.arquillian.api.Deployment;
7+
import org.jboss.arquillian.junit.Arquillian;
8+
import org.jboss.jsfunit.jsfsession.JSFClientSession;
9+
import org.jboss.jsfunit.jsfsession.JSFServerSession;
10+
import org.jboss.jsfunit.jsfsession.JSFSession;
11+
import org.jboss.shrinkwrap.api.spec.WebArchive;
12+
import org.junit.Test;
13+
import org.junit.runner.RunWith;
14+
15+
import com.ocpsoft.pretty.faces.test.PrettyFacesTestBase;
16+
17+
@RunWith(Arquillian.class)
18+
public class ViewIdMatchTest extends PrettyFacesTestBase
19+
{
20+
21+
@Deployment
22+
public static WebArchive createDeployment()
23+
{
24+
return PrettyFacesTestBase.createDeployment()
25+
.addClass(ViewIdMatchBean.class)
26+
.addResource("viewidmatch/viewidmatch.xhtml", "path/viewidmatch.xhtml");
27+
}
28+
29+
@Test
30+
public void testPatternMatchingViewId() throws Exception
31+
{
32+
33+
// Access the page
34+
JSFSession jsfSession = new JSFSession("/path/christian");
35+
JSFClientSession client = jsfSession.getJSFClientSession();
36+
JSFServerSession server = jsfSession.getJSFServerSession();
37+
38+
// Check injected value
39+
assertTrue("Wrong value injected", client.getPageAsText().contains("Injected value: [christian]"));
40+
assertEquals("christian", server.getManagedBeanValue("#{viewIdMatchBean.value}"));
41+
42+
}
43+
44+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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>ViewIdMatchTest</title>
11+
</head>
12+
13+
<body>
14+
15+
<p>
16+
Injected value: [#{viewIdMatchBean.value}]
17+
</p>
18+
19+
</body>
20+
21+
</html>

0 commit comments

Comments
 (0)