Wicket Guard #4

Simple wrapper for creating bookmarkable page links

Lets say you want to create a parametrizable bookmarkable link like this:

<a href="/cityPage?city=london">London</a>

Creating a dynamic parametrized bookmarkable link needs the following items in wicket:

  • a wicket:id for the anchor’s href
  • a key for the parameter
  • the value for the key
  • a wicket:id for the displaying the text of the link
  • the actual text itself

Here is a simple wrapper method that can do all in one stroke:

	 * Usage:
	 *   createBookmarkablePageLink("linkWicketId", Page.class, "paramKey", $param.value, "textWicketId", $text);
	public static BookmarkablePageLink createBookmarkablePageLink(String _wicketId, Class _pageClass, String _paramKey, String _paramValue, String _wicketHrefTextId, String _hrefText) {
		PageParameters param = new PageParameters();
		param.add(_paramKey, _paramValue);
		BookmarkablePageLink link = new BookmarkablePageLink(_wicketId, _pageClass, param);
		link.add(new Label(_wicketHrefTextId, _hrefText));
		return link;

Here is how the call would look for the above html:

createBookmarkablePageLink("cityLinkWicketId", CityPage.class "city", "london", "cityNameWicketId", "London");

And the corresponding wicket html:

<a wicket:id="cityLinkWicketId" href="#"><span wicket:id="cityNameWicketId">$someCityName</span></a>

4 thoughts on “Wicket Guard #4

  1. Very nicely done.
    It needs only small correction. There is missing comma between class and city (2nd and 3rd argument)


  2. How do i use this function. Will calling this function automatically genereate the url or i have to call some other function with this genereated url …I want to generate the bookmarkable link onSubmit. Please reply


    1. You have everything there the method that generate link for you, sample of caller and sample of what you need to place in your HTML. What more you want to know?


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s