Apache Wicket Merchandise

19 02 2009

In late 2008 I got the permission (by signing a contract) from ASF to create and run a Webshop that sells Wicket Merchandise, the shop donates 5% of profit to ASF the rest goes to the Wicket community. If you want to buy some merchandise go here http://www.cafepress.com/apachewicket .

The Apache Wicket Merchandise Shop has awarded these people:

The idea are to continue to use profits to award people that has done something special for the wicket community, like Wicket committers or WicketStuff committers etc.

If you have someone that you would like to nominate to receive some merchandise please write it as a comment here, please write a few lines why and if you have contact information you can mail it too me. I’ll add them to the vote list.

regards Nino


Wicket continues to impress me

11 12 2008

So I wanted to put in a conditional css thing to fix a IE problem, todo this thing in wicket I just though up a way. And wrote the code, it just worked:)

Heres how:
Markup (in head):

<style wicket:id="ieStyle" type="text/css">


A simple webmarkupcontainer, to put in the hack (with a resource reference)::

add(new WebMarkupContainer("ieStyle"){

protected void onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag) {
super.onComponentTagBody(markupStream, openTag);
String csshoverurl=urlFor(new ResourceReference(BasePage.class,"csshover2.htc")).toString();
getResponse().write("" +
"body {" +
"behavior: url("+csshoverurl+");" +



And to finish it up make it conditional so only IE picks it up, by adding a behavior:

public class IECheckBehaviorBehavior extends  AbstractBehavior {
public IECheckBehaviorBehavior() {
public void beforeRender(Component component) {
Response response = component.getResponse();
response.write("*!--[if lt IE 7]&gt;--*");
public void onRendered(Component component) {
Response response = component.getResponse();

The result:

<!--[if lt IE 7]&gt;-->
body {behavior: url(resources/zeuzgroup.web.page.BasePage/csshover2.htc;jsessionid=1pjzdpc4j8asn);}

Simple and and almost clean 🙂

Ps updated the post to show correct source

new stuff in Wicketstuff OpenLayers integration

9 12 2008

So I’ve added a few things and done a cleanup on the Wicketstuff OpenLayers integration.

  • We are now using JTS (http://www.vividsolutions.com/Jts/JTSHome.htm) directly.
  • You are now able to draw geometry’s using the new DrawListenerBehavior
    • Geom’s are pushed to java using JTS
  • Remove the drawControl using the RemoveDrawControl behavior.

Heres some screens :



FeedBack from serverside (just outputting the WKT of the geom)

interaction 01

Using a little JTS:

A little JTS power

And if you’re wondering why is this cool? Well because above interactions are passed to server side, using the Wicketstuff Openlayers integration requires no knowledge of javascript, its wrapped nicely for you.

Heres the link to a little more about the library:


And if you combine this with hibernate spatial, you can since hibernate spatial supports JTS.. You have a really cool simple GIS system 🙂

Apache Wicket javascript integration

9 09 2008

This article will give some general pointers on howto do javascript integration, it’ll give some tip on how to make it easier to for you. And also a recommended way on project structuring.

Howto do it:

Javascript bridge

If you need a javascript bridge between the javascript library and wicket a very nice way are todo it like this:

Use the wicket namespace for a cleaner approach(like above), and remember to place your data in an array, so you can have multiple of the same components on the same page. Like so:

var Wicket;
if (!Wicket) {
Wicket = {};
} else {
if (typeof Wicket != "object") {
throw new Error("Wicket already exists and is not an object");
Wicket.omaps = {};
function WicketOMap(id, options) {
Wicket.omaps[id] = this;

Lots of dynamic stuff?

If you have lots of dynamic stuff you can use a texttemplate to interpolate your variables with it works really smooth, heres an example:

HashMap variables = new HashMap();
variables.put("alert", "helloworld");
TextTemplate textTemplate=new TextTemplate();
String js= textTemplate.asString();

corrosponding java script, notice the template signature ${…}


So above code will produce a javascript string ‘alert(“hello world”)’ very useful.

Using a behaviour

Behaviours are nice if you need some special that modifies the component you want to add too. It’s an easy way of getting information like markupid etc. Its good because you can access the component that you bind to, so you may put in javascript, add attributemodifiers etc for it.

Virtual tour of Mootips

Heres a virtual tour of Mootips javascript integration

go here for the minis wiki

Screencast: introducing Wicketstuff Iolite

4 09 2008

So without further delay watch the screencast below:

Wicket Iolite 0.3

3 09 2008

So it’s out just waiting to get built on the wicketstuff teamcity server, and be made public available from there.

Wicket Iolite are a Wicketstuff project, and it’s all about making development really easy for you. It’s a archetype that setups a project for you with a two module struture web and core. In core you will find JPA entities, and in wicket you’ll find the counter wicket part.


  • Depends on domdridges project
  • Real maven archetype
  • Lots of cleaning
  • Even more simple than before

Read more here:


Pump your Java with Caching

25 08 2008

So you want caching. First thing to see are if your application are applicable for it. There’s the 80/20 rule saying that you need to be maximum 20% writing on what you intend to cache, if you deviate too much from these numbers caching stuff could actually slow you down. I had some fun with this on my own “production” machine an old p3 500mhz (keep that in mind when you see results).

Im gonna write about my current stack which are Apache Http+Apache Tomcat, JPA / Hibernate + spring & Apache Wicket, this does’nt mean that you cant benefit from the ideas though if you arent using these frameworks, which leads me to what I believe are number one rule with caching:

Non intrusion , cache needs to be applied lightly in a non intrusive way

That way you can easily switch it off, switch strategies etc.

So with my stack you can actually introduce caching in each layer if you want to, i’ll start at Hibernate.

Caching with Hibernate

As I used Hibernate and my application seemed a bit heavy on the database I optimized everything, but Hibernate I thought lets start here. So I did, enabling the query cache and 2nd level cache were actually very simple and few lines of code. But this approach were very intrusive as the application needed to know about the caching mechanism, I went ahead any how. I spent 2 days pondering why it did not work, I kept getting cache misses even though I saw that the queries were added to the cache. Hibernate forum werent being responsive so I thought maybe theres another way. Which leads me to next thing.

btw I just bought Java Persitence with Hibernate http://www.manning.com/bauer2/ to help me digg into the cache with Hibernate.

Caching with Spring modules cache

So the spring guys has an non intrusive way of applying caching. It’s really simple :

ApplicationContext.xml add:

<import resource="classpath:cacheContext.xml" />

cacheContext.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd">

  [4]<ehcache:config failQuietly="true"

    <bean id="myCacheKeyGenerator" class="zeuzgroup.core.cache.ZeuzCacheKeyGenerator"/>
    <bean id="myCachingListener" class="zeuzgroup.core.cache.ZeuzCachingListener"/>


        <ehcache:cacheKeyGenerator refId="myCacheKeyGenerator"/>

            <ehcache:cachingListener refId="myCachingListener"/>

[1]<ehcache:caching cacheName="translationCache"

<!--  Flush cache -->
    [2]<ehcache:flushing cacheNames="translationCache" methodFQN="zeuzgroup.core.localization.ITranslationService.put*" when="after"/>

    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="beanNames">
               [3] <idref bean="translations"/>
        <property name="interceptorNames">
  1. setup target methods to cache
  2. setup which metods that evict cache
  3. point at beans to look in
  4. point at ehcache.xml

As you can notice theres two beans further more defined(myCachinglistener and mycachingkeygenerator), you can just use the default implementation provided. Although you might want to use your own keygenerator if using datetime properties in your objects, if your methods return objects with new stamps your cache will not be hit. In my setup my wicket page went from 12s to display to 4s (having a 2s round trip).


<diskStore path="java.io.tmpdir" />
<defaultCache maxElementsInMemory="1000" eternal="false"
 timeToIdleSeconds="0" timeToLiveSeconds="500" overflowToDisk="true"
 diskPersistent="false" diskExpiryThreadIntervalSeconds="500" />
 <cache name="translationCache" maxElementsInMemory="75000"
eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false"
 diskExpiryThreadIntervalSeconds="3600" />

Above are also pretty straight forward.. Now onto the next part.

Caching with Wicket, or preparation for web cache.

Caching statefull pages? Well you can. But remember that if you do when others look at the page you cache they’ll get the same result. Please remember that you cant cache pages with ajax on (AFAIK).

So this means that if you have a “simple” solution where you have users that can be either authorized or not it’s pretty straight forward. I went ahead and chose all the pages where my users arent logged in to be cachable. I decided to go with ehcache’s web cache namely the simplefiltercache. And to make it visible for the cache when a page could be cachable I added a noop parameter to all my pages called cache it has the value true. The simplest way to work with a cache are using urls, you might be able to do something http codes and cache all that does not sets the cache control header. But that’s stretching it to far for me.


public abstract class MyPage extends WebPage {
public static final String CACHEABLE = "cache";

private PageParameters myPageParameters;
[1]    public Boolean canCache() {

        if (MySession.class.isInstance(this.getSession())) {
            MySession mySession = (MySession) this.getSession();
            return !mySession.isAuthorized();
        return true;
    public MyPage(PageParameters pageParameters) {
[2]	myPageParameters = pageParameters;
[3]        BookmarkablePageLink creditsLink = new BookmarkablePageLink("credits",
                CreditsPage.class, getPageParameters(getSession().getLocale()));
[4]   protected PageParameters getPageParameters(Locale locale) {
        PageParameters pageParameters = new PageParameters();
        if (canCache() && !pageParameters.containsKey(CACHEABLE)) {
            pageParameters.add(CACHEABLE, "true");
        if (!canCache()) {
        if (zeuzPageParameters != null) {
            if (pageParameters.containsKey("locale")) {

        pageParameters.add("locale", locale.getLanguage());
        return pageParameters;

Okay so 4 simple steps are needed to make our wicket pages cachable:

  1. Make a method that can determine if a page are cachable or not
  2. Keep a reference to the page parameters the page were initialized with.
  3. Use bookmarkablePageLink’s so that url’s are stable
  4. This is where the magic are done, add the cachable parameter to appropriate pages, notice that if you have a multilingual application you need that as a parameter otherwise the locale of the pages will be the one that last caused a miss.

Note : I had to set this to get stable parameter positions in urls:

        // Be able to sort page parametes

Okay so now our wicket pages can be cached, now we just setup the cache:

add in ehcache.xml

<cache name=”SimplePageCachingFilter” overflowToDisk=”true” maxElementsInMemory=”500″ timeToLiveSeconds=”86400″ timeToIdleSeconds=”43200″/>

if you want define flush methods in cacheContex.xml:

    <ehcache:flushing cacheNames="SimplePageCachingFilter" methodFQN="zeuzgroup.core.provider.IDBDao.persistExercise*" when="after"/>

For me this made the page I talked about earlier go from 4s to 0.2s to display.


So I tried several approaches before comming to the approach showed above (regarding wicket). I tried creating a custom a IRequestEncodingStrategy, did’nt work for me but it’s my fault nothing todo with wicket. Sometimes simple are better I guess. An annoying thing were that apparently that my pages when in danish locale were’nt encoded with html entities (this caused chars like æ ø å to get corrupted), i’ve submitted a patch to wicket to support this http://issues.apache.org/jira/browse/WICKET-1795 , it’s just for component though a general setting would be nice. I think above are pretty straight forward, but of course it would be nice if wicket support something like it out of the box, but then again it requires many thing that only you as the developer can decide. Using above approach you’re free to chose ehwebcachefilter like i did or something else like Apache http, if you dont select ehcache, you’ll loose the evict option. But there might be other options. The above approach should be usable with other web frameworks aswell.