You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by ta...@jakarta.apache.org on 2005/01/20 19:04:23 UTC
[Jakarta Tapestry Wiki] Updated: FriendlyUrls
Date: 2005-01-20T10:04:23
Editor: PaulFerraro
Wiki: Jakarta Tapestry Wiki
Page: FriendlyUrls
URL: http://wiki.apache.org/jakarta-tapestry/FriendlyUrls
Added fix for reset service
Change Log:
------------------------------------------------------------------------------
@@ -19,7 +19,8 @@
I chose the following URL pattern to represent Tapestry services ''with'' an associated page:
-/''page-name''.htm
+/''page-name''.htm[[BR]]
+/''page-name''.reset
I chose the following URL pattern to represent Tapestry services ''without'' an associated page:
@@ -30,6 +31,7 @@
{{{
<application name="MyApplication" engine-class="com.mycompany.BaseEngine">
<property name="org.apache.tapestry.page-url-suffix" value=".htm"></property>
+ <property name="org.apache.tapestry.reset-url-suffix" value=".reset"></property>
<property name="org.apache.tapestry.service-url-suffix" value=".do"></property>
<!-- ... -->
@@ -46,7 +48,9 @@
}}}
Generated URL = {{{/path/mylisting.htm}}}[[BR]]
- Generated URL = {{{/path/mydetail.htm}}}
+ Generated URL = {{{/path/mylisting.reset}}}[[BR]]
+ Generated URL = {{{/path/mydetail.htm}}}[[BR]]
+ Generated URL = {{{/path/mydetail.reset}}}
e.g.
@@ -135,7 +139,7 @@
||Action||{{{http://localhost/app?service=action/1/mydetail/10}}}||{{{http://localhost/path/mydetail.htm?service=action&service=1&service=10}}}||
||Home||{{{http://localhost/app?service=home}}}||{{{http://localhost/home.do}}}||
||Restart||{{{http://localhost/app?service=restart}}}||{{{http://localhost/restart.do}}}||
-||Reset||{{{http://localhost/app?service=reset}}}||{{{http://localhost/reset.do}}}||
+||Reset||{{{http://localhost/app?service=reset/mydetail}}}||{{{http://localhost/path/mydetail.reset}}}||
||Custom||{{{http://localhost/app?service=myservice&sp=21}}}||{{{http://localhost/path/myservice.do?sp=21}}}||
After deciding on the URL scheme, the next step was to create an implementation of ILink that can generate the new URLs:
@@ -576,9 +580,28 @@
*/
public ILink getLink(IRequestCycle requestCycle, IComponent component, Object[] parameters)
{
- String suffix = requestCycle.getEngine().getSpecification().getProperty(BaseEngine.SERVICE_URL_SUFFIX);
+ if (Tapestry.size(parameters) != 1)
+ {
+ throw new IllegalArgumentException(Tapestry.format("service-single-parameter", Tapestry.RESET_SERVICE));
+ }
+
+ String page = (String) parameters[0];
+
+ String suffix = requestCycle.getEngine().getSpecification().getProperty(BaseEngine.RESET_URL_SUFFIX);
- return new Link(requestCycle, Tapestry.RESET_SERVICE + suffix, null, null);
+ return new Link(requestCycle, page + suffix, null, null);
+ }
+
+ /**
+ * @see org.apache.tapestry.engine.AbstractService#getServiceContext(org.apache.tapestry.request.RequestContext)
+ */
+ protected String[] getServiceContext(RequestContext requestContext)
+ {
+ IApplicationSpecification specification = requestContext.getServlet().getApplicationSpecification();
+ String urlSuffix = specification.getProperty(BaseEngine.RESET_URL_SUFFIX);
+ String servletPath = requestContext.getRequest().getServletPath();
+
+ return new String[] { servletPath.substring(1, servletPath.indexOf(urlSuffix)) };
}
}
}}}
@@ -606,6 +629,7 @@
{
public static final String SERVICE_URL_SUFFIX = "org.apache.tapestry.service-url-suffix";
public static final String PAGE_URL_SUFFIX = "org.apache.tapestry.page-url-suffix";
+ public static final String RESET_URL_SUFFIX = "org.apache.tapestry.reset-url-suffix";
/**
* @see org.apache.tapestry.engine.AbstractEngine#extractServiceName(org.apache.tapestry.request.RequestContext)
@@ -644,6 +668,13 @@
{
return servletPath.substring(1, servletPath.indexOf(serviceUrlSuffix));
}
+
+ String resetUrlSuffix = specification.getProperty(RESET_URL_SUFFIX);
+
+ if (servletPath.endsWith(resetUrlSuffix))
+ {
+ return Tapestry.RESET_SERVICE;
+ }
throw new ApplicationRuntimeException("Invalid request: " + requestContext.getRequest().getRequestURL());
}
@@ -668,6 +699,10 @@
<servlet-mapping>
<servlet-name>MyApplication</servlet-name>
<url-pattern>*.htm</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>MyApplication</servlet-name>
+ <url-pattern>*.reset</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MyApplication</servlet-name>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org