Wicket 1.5 and obtaining a URL to page instance
Asked Answered
L

3

8

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.

Leverett answered 6/3, 2012 at 8:17 Comment(0)
M
10

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...

Magus answered 6/3, 2012 at 8:17 Comment(3)
Actually doing this also works and it's shorter: getRequestCycle().urlFor(YourPage.class, null)Bel
@Glide: No. This is not the same. The OP asks for page instance.Magus
Yup, disregard my comment.Bel
A
0

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)

Angloirish answered 6/3, 2012 at 11:27 Comment(3)
That is not the problem. The problem is that interface for urlFor() method changed in 1.4->1.5 upgrade.Doubling
that generates a static link to MyPage where new MyPage instance is created with no-args or PageParameters constructor. I need a version that creates an URL for existing page instance (new MyPage("somevalue", "someothervalue", etc) )Doubling
Downvoted because the question was explicitly about a page instance (not a page type).Joint
A
-1

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

Adjudication answered 6/3, 2012 at 15:30 Comment(2)
This only works with page instances that have no-args constructor or ones that take PageParameters as parameter. MyPage is neither.Doubling
Downvoted because the question was explicitly about a page instance (not a page type).Joint

© 2022 - 2024 — McMap. All rights reserved.