Search code examples
wicketwicket-6wicket-1.6

One URL, which can display one of two Wicket pages based on database content


I want to achieve the following using Apache Wicket.

We have the requirement that the URL /xxxx can display one of two things.

  • If there is an entry in the "city" table (column "url_name") then we should display the CityDetailPage.
  • If there is an entry in the "venue" table (column "url_name") then we should display the VenueDetailPage.

These are quite distinct pages, with hundreds of lines of various wicket components and so on.

Currently we had two different URLs (/city/xxx and /venue/xxx) and they were mapped in the application, and that worked fine. Now they should share a URL.

I need to have some kind of logic like "select id from city where url_name=?" and if there is a row display the CityDetailPage, else if "select id from venue where url_name=?" then VenueDetailPage, otherwise 404.

Things I've considered:

  • Have one huge page with two sections which are visible/invisible based on what's found. But that's quite inelegant, these are two different pages basically.
  • Have a Servlet which looks at the path and does the db query then an internal redirect (we have Apache in front of our Servlet engine). Also feels inelegant, it's outside wicket.
  • Maybe some Page which does nothing more than some kind of wicket exception which displays another page (but does not alter the URL), not sure which type to use?

Thanks in advance! I am quite stuck :(


Solution

  • I'd recommend to use custom IProvider, i.e. instead of mountPage("the/path", VenuePage.class) do mount(new MountedMapper("the/path", new MyClassProvider())), where MyClassProvider implements IProvider and returns different page class in #get() depending on your conditions.