Author: manaRH
Date: 2013-06-03 09:19:51 -0400 (Mon, 03 Jun 2013)
New Revision: 15510
Added:
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/faces/TestComponent.java
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/faces/ViewUrlBuilderTest.java
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/WEB-INF/components-rewrite.xml
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/WEB-INF/rewrite-web.xml
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/testslink.xhtml
Modified:
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/util/ViewUrlBuilder.java
Log:
JBSEAM-5085 fixed ViewUrlBuilder to not break Page rewrite of UICommandComponents
Modified:
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/util/ViewUrlBuilder.java
===================================================================
---
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/util/ViewUrlBuilder.java 2013-06-03
13:19:31 UTC (rev 15509)
+++
branches/enterprise/WFK-2_1/jboss-seam-ui/src/main/java/org/jboss/seam/ui/util/ViewUrlBuilder.java 2013-06-03
13:19:51 UTC (rev 15510)
@@ -2,6 +2,10 @@
package org.jboss.seam.ui.util;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
@@ -13,6 +17,7 @@
{
private Page page;
+ private String viewId;
public ViewUrlBuilder(String viewId, String fragment, boolean urlEncodeParameters)
{
@@ -22,16 +27,18 @@
throw new NullPointerException("viewId must not be null");
}
FacesContext facesContext = FacesContext.getCurrentInstance();
- String url =
facesContext.getApplication().getViewHandler().getBookmarkableURL(facesContext, viewId,
null, false);
- url = Pages.instance().encodeScheme(viewId, facesContext, url);
+ // will use bookmarkable URL later in getEncodeUrl() method which already knows all
added Parameters
+ //String url =
facesContext.getApplication().getViewHandler().getBookmarkableURL(facesContext, viewId,
null, false);
+ String url =
facesContext.getApplication().getViewHandler().getActionURL(facesContext, viewId);
+ url = Pages.instance().encodeScheme(viewId, facesContext, url);
setUrl(url);
-
- page = Pages.instance().getPage(viewId);
+ this.page = Pages.instance().getPage(viewId);
+ this.viewId = viewId;
}
public ViewUrlBuilder(String viewId, String fragment)
{
- this(viewId, fragment, true);
+ this(viewId, fragment, false);
}
@@ -47,7 +54,26 @@
}
@Override
- public String getEncodedUrl() {
- return
FacesContext.getCurrentInstance().getExternalContext().encodeActionURL(super.getEncodedUrl());
+ public String getEncodedUrl()
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ return
facesContext.getApplication().getViewHandler().getBookmarkableURL(facesContext,
this.viewId, getParametersAsMap(getParameters()), false);
}
+
+ /*
+ * Converts Seam parameters Map <String,String> to JSF 2
Map<String,List<String>>
+ */
+ private Map<String,List<String>> getParametersAsMap(Map
<String,String> params)
+ {
+ Map<String,List<String>> parameters = new HashMap<String,
List<String>>();
+
+ for(Map.Entry<String, String> entry : params.entrySet())
+ {
+ List<String> list = new ArrayList<String>();
+ list.add(entry.getValue());
+ parameters.put( ((String) entry.getKey()), list);
+ }
+
+ return parameters;
+ }
}
Added:
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/faces/TestComponent.java
===================================================================
---
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/faces/TestComponent.java
(rev 0)
+++
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/faces/TestComponent.java 2013-06-03
13:19:51 UTC (rev 15510)
@@ -0,0 +1,28 @@
+package org.jboss.seam.test.integration.faces;
+
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Out;
+
+/**
+ * Test Seam component for ViewUrlBuilderTest and s:link rewrite feature
+ * @author mnovotny
+ *
+ */
+@Name("testslink")
+public class TestComponent
+{
+ @In(required=false) @Out(required=false) String input;
+
+ public String getInput()
+ {
+ return input;
+ }
+
+ public void setInput(String input)
+ {
+ this.input = input;
+ }
+
+
+}
Added:
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/faces/ViewUrlBuilderTest.java
===================================================================
---
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/faces/ViewUrlBuilderTest.java
(rev 0)
+++
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/faces/ViewUrlBuilderTest.java 2013-06-03
13:19:51 UTC (rev 15510)
@@ -0,0 +1,73 @@
+package org.jboss.seam.test.integration.faces;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URL;
+
+import javax.validation.constraints.AssertTrue;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.OverProtocol;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.seam.test.integration.Deployments;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+
+(a)RunWith(Arquillian.class)
+@RunAsClient
+public class ViewUrlBuilderTest
+{
+ @ArquillianResource
+ URL contextPath;
+
+ private final WebClient client = new WebClient();
+
+ @Deployment(name="ViewUrlBuilderTest")
+ @OverProtocol("Servlet 3.0")
+ public static Archive<?> createDeployment()
+ {
+ // This is a client test, use a real (non-mocked) Seam deployment
+ WebArchive war = Deployments.realSeamDeployment().addClasses(TestComponent.class);
+ war.delete("WEB-INF/pages.xml");
+ war.delete("WEB-INF/components.xml");
+ war.delete("WEB-INF/web.xml");
+
+ war.addAsWebInfResource(new StringAsset(
+ "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n" +
+ "<pages
xmlns=\"http://jboss.org/schema/seam/pages\""
+
+ "
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
+ "
xsi:schemaLocation=\"http://jboss.org/schema/seam/pages
http://jboss.org/schema/seam/pages-2.3.xsd\">\n" +
+ "<page view-id=\"/testslink.xhtml\">"+
+ "<rewrite pattern=\"/testslink/{input}\" />" +
+ "<rewrite pattern=\"/testslink\" />"+
+ "<param name=\"input\"
value=\"#{testslink.input}\"/>" +
+ "</page></pages>"), "pages.xml")
+ .addAsWebResource("testslink.xhtml","testslink.xhtml")
+
.addAsWebResource("WEB-INF/components-rewrite.xml","WEB-INF/components.xml")
+
.addAsWebResource("WEB-INF/rewrite-web.xml","WEB-INF/web.xml");
+
+ return war;
+ }
+
+ @Test
+ public void testRewriteSeamLink() throws Exception
+ {
+ HtmlPage page = client.getPage(contextPath + "testslink/1");
+ // second request eliminates ";jsessionid=[a-Z0-9] parameter
+ page = client.getPage(contextPath + "testslink/1");
+ assertTrue(!page.asText().isEmpty());
+ String href =
page.getElementById("form:testslink").getAttribute("href");
+ assertEquals("/test/testslink/1", href);
+ }
+
+
+}
Added:
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/WEB-INF/components-rewrite.xml
===================================================================
---
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/WEB-INF/components-rewrite.xml
(rev 0)
+++
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/WEB-INF/components-rewrite.xml 2013-06-03
13:19:51 UTC (rev 15510)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<components
xmlns="http://jboss.org/schema/seam/components"
+
xmlns:core="http://jboss.org/schema/seam/core"
+
xmlns:web="http://jboss.org/schema/seam/web"
+
xmlns:persistence="http://jboss.org/schema/seam/persistence"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation=
+ "http://jboss.org/schema/seam/core
http://jboss.org/schema/seam/core-2.3.xsd
+
http://jboss.org/schema/seam/components
http://jboss.org/schema/seam/components-2.3.xsd
+
http://jboss.org/schema/seam/web
http://jboss.org/schema/seam/web-2.3.xsd
+
http://jboss.org/schema/seam/persistence
http://jboss.org/schema/seam/persistence-2.3.xsd" >
+
+ <core:init debug="false"
jndi-pattern="java:app/test/#{ejbName}" />
+
+ <core:manager concurrent-request-timeout="500"
+ conversation-timeout="120000"
+ conversation-id-parameter="cid"/>
+
+ <web:rewrite-filter view-mapping="/seam/*"/>
+
+ <persistence:managed-persistence-context name="entityManager"
+ auto-create="true"
+
persistence-unit-jndi-name="java:/integrationEntityManagerFactory" />
+
+</components>
Added:
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/WEB-INF/rewrite-web.xml
===================================================================
---
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/WEB-INF/rewrite-web.xml
(rev 0)
+++
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/WEB-INF/rewrite-web.xml 2013-06-03
13:19:51 UTC (rev 15510)
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="3.0"
+
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-app_3_0.xsd">
+
+ <listener>
+ <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
+ </listener>
+
+ <listener>
+ <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
+ </listener>
+
+ <filter>
+ <filter-name>Seam Filter</filter-name>
+ <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>Seam Filter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <servlet>
+ <servlet-name>Seam Resource Servlet</servlet-name>
+
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Seam Resource Servlet</servlet-name>
+ <url-pattern>/seam/resource/*</url-pattern>
+ </servlet-mapping>
+
+ <!-- Faces Servlet -->
+
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>/seam/*</url-pattern>
+ </servlet-mapping>
+
+ <!-- JSF parameters -->
+
+ <context-param>
+ <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
+ <param-value>.xhtml</param-value>
+ </context-param>
+
+ <context-param>
+ <param-name>facelets.DEVELOPMENT</param-name>
+ <param-value>true</param-value>
+ </context-param>
+
+</web-app>
Added:
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/testslink.xhtml
===================================================================
--- branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/testslink.xhtml
(rev 0)
+++
branches/enterprise/WFK-2_1/seam-integration-tests/src/test/resources/testslink.xhtml 2013-06-03
13:19:51 UTC (rev 15510)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!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"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:s="http://jboss.org/schema/seam/taglib"
+ xml:lang="en"
+ lang="en">
+
+<f:view>
+ <h:head>
+ <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
+ </h:head>
+ <h:body>
+ <h:form id="form">
+ <h:inputText value="#{testslink.input}" size="20"
required="true" id="input"/>
+ <s:link id="testslink" view="/testslink.xhtml"
propagation="none" value="RecreateLink">
+ <f:param name="input" value="#{testslink.input}"/>
+ </s:link>
+ </h:form>
+ </h:body>
+</f:view>
+
+</html>