Search code examples
wicketwicket-6wicket-1.6

Apache Wicket event on Page "page was mouted on ..."


I have mount Page in this form (with one predefined parameter):

mountPage("/lista/${variant}", StronaEntityV2.class);

when parameter "variant" is given all is OK. But when parameter is absent (is OK too from application point of view) URL is build in form

wicket/bookmarkable/all....package...StronaEntityV2?8

It is ok too, but I will know that situation. In simple situation (with one predefined parameter) checking parameter is good, but in more complicated isn't so simple (and must maintain code in distinct places). My ideal imaged solution is event

page.OnPageIsMountedOn(URL to_me)

I will accept wide range of solutions.

FORMAL: please integrate synonyms on tags wicket-1.6 & wicket-6, and create new wicket-7


Solution

  • Your page is configured to listen to /lista/${variant}.

    When you do: setResponsePage(StronaEntityV2.class, paramsWithVariant) then Wicket will use the mount point and produce: /lista/variantValue.

    But if you do: setResponsePage(StronaEntityV2.class), i.e. no PageParameters provided, then Wicket will ignore /lista/${variant} (because it doesn't match) and will produce a "default" page url, i.e. /wicket/bookmarkable/com.example.StronaEntityV2.

    So the application controls which url should be used.

    You can use optional parameter placeholder: /lista/#{variant}. Note that I use # instead of $ now. This way Wicket will produce /lista/ when there is no variant parameter provided. In the page constructor you will know that the url is always "/lista" but the parameter may be null, so better use: pageParameters.get("variant").toXyz(defaultValue) or .toOptionalXyz().