Wicket in Action

A comprehensive guide for Java developers building Wicket-based web applications

Apache Wicket 1.4 takes type safety to the next level

The Apache Wicket project is proud to announce the release of Apache Wicket 1.4. Apache Wicket is an open source, component oriented Java web application framework. With overwhelming support from the user community, this release marks a departure from the past where we leave Java 1.4 behind and we require Java 5 as the minimum JDK version. By moving to Java 5 as the required minimum platform, we were able to utilize Java 5 idioms and increase the type safety of our APIs. Using Java generics you can now write typesafe web applications and create typesafe, self documenting, reusable custom components.

Download Apache Wicket 1.4

You can download the release here: http://www.apache.org/dyn/closer.cgi/wicket/1.4.0

Or use this in your Maven pom’s to upgrade to the new version:

<dependency>
  <groupId>org.apache.wicket</groupId>
  <artifactId>wicket</artifactId>
  <version>1.4.0</version>
</dependency>

You will need to upgrade all modules (i.e. wicket, wicket-extensions) to their 1.4 counterparts. It is not possible to mix Wicket 1.3 libraries with 1.4 libraries due to API changes.

Most notable changes

From all the changes that went into this release, the following are the most important ones:

  • Generified IModel interface and implementations increases type safety in your Wicket applications
  • Component#getModel() and Component#setModel() have been renamed to getDefaultModel() and setDefaultModel() to better support generified models
  • The Spring modules have been merged (wicket-spring-annot is now obsolete, all you need is wicket-spring)
  • Many API’s have been altered to better work with Java 5’s idioms
  • Wicket jars are now packaged with metadata that makes them OSGI bundles

Apart from these changes, the release is mostly compatible with Wicket 1.3 and upgrading shouldn’t take too long. Early adopters report about a days work to upgrade medium to large applications to Wicket 1.4. Read the migration guide to learn more about the changes in our APIs. To learn more about all the improvements and new features that went into this release, check the solved issue list in our JIRA instance.

Increased type safety

Moving towards Java 5 has given us the opportunity to utilize generics and clarify our API’s. For example, take a look at DropDownChoice—one of the components with the most questions on our list prior to 1.4. A DropDownChoice component is a form component that displays a list of available choices in a drop down box, and allows one selection to be made. DropDownChoice components are typically used to display a list of countries, nationalities, credit card processors, etc.

The signature of a constructor for the DropDownChoice component in Wicket 1.3 was:

public class DropDownChoice extends ...
    public DropDownChoice(String id, IModel model, IModel choices)
}

As you can see, this constructor doesn’t give much insight into what goes where (other than the names of the parameters). The first parameter is the component identifier, the second parameter is the model that contains the selection, and the third parameter is a model that contains the list of choices from which the user can select one. You’ll have to read the JavaDoc to assign the right IModel values to the right parameters. Now take a look at the same constructor, but now in Wicket 1.4. The signature for our generified constructor looks like the following example.

public <T> DropDownChoice extends ...
    public DropDownChoice(String id, IModel<T> model, IModel<? extends List<? extends T>> choices)
}

Here we communicate that the first IModel parameter is a T, which is the single value that will be provided when the DropDownChoice selects one value. The second parameter provides a List of objects that extend T, the choices from which to select one value. This was not apparent in the Wicket 1.3 API, and the type safety brought by generics make this much more clear, albeit much more verbose.

Removal of default model from component

In Wicket 1.3 each component had by default a model: a Label had a model, a Link and even WebMarkupContainer had a model property (all because they extend Component which has a model property). When we generified IModel, this had averse effects on Component: suddenly *all* components had to be generified and had to take the type parameter of the model that was associated with it. But that poses problems for components that either do not use a model or use two different model types: which one should be in the lead? We chose to generify only the components that clearly benefited from the extra type information, leading to clean code like this:

ListView<Person> peopleListView = new ListView<Person>("people", people) {
        protected void populateItem(ListItem<Person> item) {
            item.add(new Link<Person>("editPerson", item.getModel()){
                public void onClick() {
                    Person p = getModelObject();
                    setResponsePage(new EditPersonPage(p));
                }
            });
        }
    };

Support

As always, the user lists are very active, and if you need help upgrading or just want to discuss this release, send an email to the users list. More information about the community and mailing lists can be found at http://wicket.apache.org/community.html

6 Comments »

  1. Hooray! Very exciting stuff, can’t wait to try it out…

    Comment by Jason Duke — July 30, 2009 @ 4:27 pm

  2. Wicket 1.3 is dead, long live Wicket 1.4 !! :D

    Great work guys!

    Cheers,
    Bruno

    Comment by Bruno Borges — July 30, 2009 @ 7:03 pm

  3. Congrats guys, we’re using 1.4 for quite a while now and it’s great!

    Comment by Rob Sonke — August 1, 2009 @ 12:23 pm

  4. i have been waiting for this one for a while!
    thank you very much for the hard work!
    i will migrate all my websites to 1.4 as soon as possible, and remove all those ugly casts :D

    david

    Comment by david_p — August 13, 2009 @ 12:32 am

  5. You are amazing! Thanks for all your work!

    Also, incidentally, how do I view older posts on this site? Perhaps I’m blind, but I don’t see any link to older posts at the bottom of the page…

    Comment by Dane — August 18, 2009 @ 1:13 am

  6. i have been waiting for this one for a while!
    thank you very much for the hard work!
    i will migrate all my websites to 1.4 as soon as possible, and remove all those ugly casts :D

    david

    Comment by VA — October 5, 2009 @ 11:33 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

With this book, Wicket will become the greatest territory the Dutch have settled since Manhattan.

Nathan Hamblen
Senior Software Engineer, Teachscape Inc.

This is the complete and authoritative guide to Wicket, written and reviewed by the core members of the Apache Wicket team. If there's anything you want to know about Wicket, you are sure to find it in this book.

Jonathan Locke
Founder and Architect of Apache Wicket, Foreword Wicket in Action

Without question, Wicket in Action... is the be-all and end-all when it comes to Wicket.

Geertjan Wielenga, Wicket Netbeans Plugin Author

The tutorial and conversational tone of the writing makes the book very approachable.

Nick Heudecker
System Mobile

Loved the sample application—it tied everything together.

Phil Hanna
Senior Software Developer, SAS Institute

The essential guide for learning and using Wicket.

Erik van Oosten
Lead programmer and Project Manager, JTeam

Finally, the Web Framework of web frameworks, Apache Wicket, now has a bible of its own.

Per Ejeklint
Senior Software Architect, Heimore group

Wicket is an innovative evolution of the MVC programming with simple roots, but without a primer such as this, it can be more challenging than it needs to be.

Brian Topping
Founder, Bill2 Inc.

Wicket In Action glues the areas of web development with Apache Wicket together and gives a great overview of Apache Wicket...it will make a great compendium.

Nino Martinez Wael
Java Specialist, Jayway Denmark