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.

Was it helpful?

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

org.apache.wicket.RequestCycle.urlFor was renamed to org.apache.wicket.request.cycle.RequestCycle.urlFor (See here)

[edit] My bad. Try

RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(urlFor(MyPage.class,null).toString()));

(taken from here)

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
scroll top