Encodes and decodes mounts for a single bookmarkable page class, but with the
parameters appended in a URL query string rather than integrated into a URL
hierarchical path.
For example, whereas
org.apache.wicket.request.target.coding.BookmarkablePageRequestTargetUrlCodingStrategy BookmarkablePageRequestTargetUrlCodingStrategy might encode a request target as
"mywebapp/myservlet/admin/productmanagement/action/edit/product/4995",
QueryStringRequestTargetUrlCodingStrategy would encode the
same target as
"mywebapp/myservlet/admin/productmanagement?action=edit&product=4995".
URLs encoded in this way can be bookmarked just as easily as those produced
by BookmarkablePageRequestTargetUrlCodingStrategy . For
example, Google searches produce bookmarkable links with query strings.
Whether BookmarkablePageRequestTargetUrlCodingStrategy or
QueryStringRequestTargetUrlCodingStrategy is appropriate for a
given mount depends on:
- Aesthetic criteria
- Interpretations of RFC 3986. This
defines the URI standard, including query strings, and states that whereas
the "path component contains data, usually organized in hierarchical form
[divided by slashes]", the "query component [after the question mark]
contains non-hierarchical data".
- Findability. Public search engines prefer URLs with parameters stored
hierarchically or in a shorter query string. Google's Design
and Content Guidelines (as of May 6 2006) state: "Make a site with a
clear hierarchy and text links. Every page should be reachable from at least
one static text link. … If you decide to use dynamic pages (i.e., the
URL contains a '?' character), be aware that not every search engine spider
crawls dynamic pages as well as static pages. It helps to keep the parameters
short and the number of them few."
- The complexity of the parameters being passed. More complex parameters
may make more sense expressed as a series of "key=value(s)" pairs in a query
string than shoehorned into a hierarchical structure.
Regardless of which coding strategy is chosen for the mount,
org.apache.wicket.markup.html.link.BookmarkablePageLink BookmarkablePageLink can be used to insert a bookmarkable link to the request target.
This example demonstrates how to mount a path with
QueryStringRequestTargetUrlCodingStrategy within the
init method of a class implementing
org.apache.wicket.protocol.http.WebApplication WebApplication :
mount(new QueryStringRequestTargetUrlCodingStrategy("/admin/productmanagement",
admin.ProductManagement.class));
Note that, as with the main BookmarkablePageRequestTargetUrlCodingStrategy,
if the output of this coding strategy is passed through
javax.servlet.http.HttpServletResponse.encodeURL(java.lang.String) HttpServletResponse.encodeURL and the client has cookies turned off, the client's session ID will be stored
in a path parameter, like so:
"/mywebapp/myservlet/admin/productmanagement;jsessionid=730EC527564AF1C73F8C2FB19B604F55?action=edit&product=4995".
author: Benjamin Hawkes-Lewis |