Getting a non-relative (absolute) URL for a Wicket page
Published Tue, 12 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.
You might also enjoy reading -
- Demystifying HttpServletRequest properties...
- visural-wicket 0.5 released - ready for action!
- Announcing - visural-wicket
- 301 Redirects Made Easy In Java