Blog About Contact

Getting a non-relative (absolute) URL for a Wicket page

Published Mon, 11 Oct 2010 • 2 comments

Just a quick Wicket tid-bit I found today - generally with Wicket, when you create a BookmarkablePageLink or use "urlFor(...)", the resulting URL is stated as a relative path, e.g. "../../something/mypage" (i.e. those that contain "..").

Sometimes you need to get a "fully qualified" URL such as "/pages/something/mypage" or "http://localhost:8080/myapp/pages/something/mypage".

Although there is nothing on the core Wicket objects to do this, there is a little utility included with Wicket which will allow you to convert a relative URL to an absolute URL - org.apache.wicket.protocol.http.RequestUtils

It's dead simple to use - just call RequestUtils.toAbsolutePath(...) and pass in the relative URL as a string. Assuming the relative URL was generated from the current Wicket Page, it will convert from "../../something/mypage" to "http://localhost:8080/myapp/pages/something/mypage"


About the Author

Richard Nichols is an Australian software engineer with a passion for making things.

Follow him on twitter or subscribe by RSS or email.

You might also enjoy reading -

Discuss / Comment

There are 2 comments.

Add a comment

  • {{e.error}}

Thanks for your comment!/

Valid email address required.
Posting message, please wait...