I am using Wicket 1.5 as web layer for application. I needed a page that could take parameter but it should be optional.
So I have an URL like this http://example.com/search/keyword/1, it has 2 parameters search (keyword) and page (1), but I want page to be optional, so that URL like example.com/search/keyword should be mapped to the same page.
I tried to map it with mountPage(“/search/${keyword}/${page}”, SearchPage.class);
But the problem was that page parameter was mandatory.
Solution was found here : wicketinaction.com, a blog by Martijn Dashorst
Martijn Dashorst says:
So I used # instead of dollar! mountPage(“/search/${keyword}/#{page}”, SearchPage.class); and it works!
So I have an URL like this http://example.com/search/keyword/1, it has 2 parameters search (keyword) and page (1), but I want page to be optional, so that URL like example.com/search/keyword should be mapped to the same page.
I tried to map it with mountPage(“/search/${keyword}/${page}”, SearchPage.class);
But the problem was that page parameter was mandatory.
Solution was found here : wicketinaction.com, a blog by Martijn Dashorst
Martijn Dashorst says:
One more cool thing is that you can have optional indexed named parameters. The difference with mandatory ones is that they use hash sign instead of dollar sign – #{optional}.
A mapping like mountPage(“/mount/path/${named1}/#{named2}”, MyPage.class); will match for both requests http://host/mount/path/value1 and http://host/mount/path/value1/value2.
So I used # instead of dollar! mountPage(“/search/${keyword}/#{page}”, SearchPage.class); and it works!
hello one question,
ReplyDeletemy map is
mountPage("/page/#{code}/#{name}", Page.class);
but when I click on the link
localhost/page/10/toy?2
wicket add also one parameter like a counter, when I refresh the page I have
localhost/page/10/toy?3
why?
Hey Thanks for sharing...
ReplyDeleteFinally i was able to make some cool URL and they help me in creating dynamic Web Pages.