Wicket 1.5 and obtaining a URL to page instance
-
08-12-2019 - |
Question
What is to correct way in Wicket 1.5 to obtain URL to a page instance?
In Wicket 1.4.x this worked:
MyPage page = new MyPage(some, parameters);
getRequestCycle().urlFor(page).toString()
A bunch of different versions of urlFor()
were removed from RequestCycle in Wicket 1.5, among these were urlFor(Page page) that I was using in Wicket 1.4.
Solution
You need: org.apache.wicket.request.cycle.RequestCycle#urlFor(IRequestHandler).
cycle.urlFor(new RenderPageRequestHandler(new PageProvider(page)))
I'm not sure why this wasn't migrated. I guess because it is not used widely...
OTHER TIPS
Try
RequestUtils.toAbsolutePath(urlFor(MyPage.class, params).toString(), "/");
See JavaDoc of RequestUtils and Component as suplier for urlFor for the (scarce) details... But the interface should be pretty selfexplaining. Just supply the target class and the PageParams-Object and be (mostly) done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow