Wednesday, November 05, 2008

Add a favicon to your page - Wicket

You can add the favicon to all the pages of your website with a simple HeaderContributor.

Below is a simple static method which returns a headercontributor behavior:

class WicketUtils {

   public static HeaderContributor headerContributorForFavicon(final ResourceReference reference)
{
     return new HeaderContributor(new IHeaderContributor() {
                     private static final long serialVersionUID = 1L;

          public void renderHead(final IHeaderResponse response) {
                               response.renderString("<link type=\"image/x-icon\" rel=\"shortcut icon\" href=\"resources/favicon.ico\" />");
                     }
       });
   }
}

call it in your abstract web page constructor.

public abstract class MyAbstractWebPage extends WebPage {

MyAbstractWebPage() {
   add(WicketUtils.headerContributorForFavicon());
}


No comments: