2012-12-13

Wicket and nice URLs – URL coding strategies

Intro: http://www.javalobby.org/…/t68753.html

Not much nice wiki page – almost useless, just aggregated JavaDoc's

URL coding strategies

BookmarkablePa­geRequestTarge­tUrlCodingStra­tegy example

http://localhost/app/mountPath/param1/value1/param2/value2

// [in AlohaApplication.init()]
mountBookmarkablePage("/mountPath", MyPage.class);

pageParameters.getString("param1"); // "value1"
pageParameters.getString("param2"); // "value2"

IndexedParamUr­lCodingStrate­gy example

http://localhost/app/mountPath/value1/value2

pageParameters.getString("0"); // "value1"
pageParameters.getString("1"); // "value2"

HybridUrlCodin­gStrategy example

„The url with HybridUrlCodin­gStrategy looks like /mount/path/param1/value1.3. or /mount/path/param1/value1.3.2 where 3 is page ID and 2 is version number.“ I haven't tried this yet.

http://localhost/app/mountPath/param1/value1.3.2

pageParameters.getString("param1"); // "value1"
// what else?

PackageReques­tTargetUrlCodin­gStrategy example

 + cz.dynawest.wicketdemo
 |--HomePage.class
 |--HomePage.html
 |--Contacts.class
 \--Contacts.html


// [in AlohaApplication.init()]
mount("/main", PackageName.forClass(HomePage.class));


http://localhost/app/mountPath/HomePage/param1/value1/param2/value2
http://localhost/app/mountPath/Contacts/param1/value1/param2/value2

pageParameters.getString("param1"); // "value1"
pageParameters.getString("param2"); // "value2"

QueryStringUr­lCodingStrate­gy example

The PHP way. JavaDoc

http://localhost/app/mountPath?param1=value1&param2=value2

// [in AlohaApplication.init()]
private <C extends Page> void mountBookmarkablePageWithUrlCoding(String path, Class<C> pageClass)
{
  mount(new QueryStringUrlCodingStrategy(path, pageClass));
}


pageParameters.getString("param1"); // "value1"
pageParameters.getString("param2"); // "value2"

MixedParamUrlCo­dingStrategy example (JavaDoc)

Url coding strategy for bookmarkable pages that encodes a set of given parameters in the url's path and the rest in the query-string.

Strategy looks for path-parameters whose name is read from an array of names e.g. [„param0“, „param1“]. Found parameters will be appended to the url in the form

http://localhost/app/mountPath/paramvalue0/valueA/valueB?param1=value1&param2=value2

// [in AlohaApplication.init()]

String[]{"paramA","paramB"}

pageParameters.getString("paramA"); // "valueA"
pageParameters.getString("paramB"); // "valueB"
pageParameters.getString("param1"); // "value1"
pageParameters.getString("param2"); // "value2"

JavaDoc errata:
„When both "b“ and „c“ are missing on encode, they will not get a value during decode."

CryptedUrlWeb­RequestCodingStra­tegy example

TBD

http://localhost/app/mountPath/value1/value2

pageParameters.getString("0"); // "value1"
pageParameters.getString("1"); // "value2"

0