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.

Juha Syrjälä
  • 33,425
  • 31
  • 131
  • 183

3 Answers3

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

martin-g
  • 17,243
  • 2
  • 23
  • 35
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)

Joachim Rohde
  • 5,915
  • 2
  • 29
  • 46
  • That is not the problem. The problem is that interface for urlFor() method changed in 1.4->1.5 upgrade. – Juha Syrjälä Mar 06 '12 at 11:38
  • 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) ) – Juha Syrjälä Mar 06 '12 at 14:52
  • Downvoted because the question was explicitly about a page instance (not a page type). – bernardn Jun 04 '12 at 12:32
-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

Nicktar
  • 5,548
  • 1
  • 28
  • 43