Sometimes it is very helpful to read old messages in your mail archive. I found a short discussion where I promised Stefan Arentz that we would incorporate some code he sent to the mailinglist into our examples. Well, of course I forgot all about it, and just 5 minutes ago rediscovered his message and example. So without any delay: here's a page counter component made in Wicket:

Stefan Arentz wrote:

As an experiment I create a little counter panel. The markup looks like this:



    123

And this is the code (quick hack, not thread safe):

public class Counter extends Panel
{
    static Map mCounters = new HashMap();
    private String mCounterName;

    public Counter(String componentName, String counterName)
    {
        super(componentName);
        mCounterName = counterName;
        Integer count = (Integer) mCounters.get(mCounterName);
        if (count == null) {
            count = new Integer(1);
        } else {
            count = new Integer(count.intValue() + 1);
        }
        mCounters.put(mCounterName, count);
        add(new Label("count", count.toString()));
    }
}

Pretty simple. And I can now make different counters for pages like this:

Markup:

Java:

add(new Counter("counter", "HomepageCounter"));

The fun part is, that this is a full fledged component, that can be put in a jar, put in the classpath of your webapplication, and all you have to do is use the two little fragments at the end of the quote, to incorporate the hit counter in your page(s).

I like the simplicity of this example. It doesn't take rocket science to create such a component. It doesn't take any XML to create or use this component. Now that is where JSF still has something to gain.