The road so far….

May 7, 2010

Apache Wicket for GUI playground

Filed under: java — Tags: , — Rahul Sharma @ 10:16 pm

I have been evaluating  Apache Wicket for over a month now and I must say that I am pretty impressed by the way the framework has been organised.For starters the concepts employed are quite straight forward and simple .

Players Involved:

You have an HTML page that needs to be displayed. The data that this page needs is contained in you custom WebPage class, having the same name as that of the HTML page. The only restriction is that every field in the class should be Serializable else Wicket would throw exceptions on the container console, but will still work on the client browser. Keep both of these components the HTML page and the corresponding Java class at the same location and Wicket will relate them with one another.

Now by this approach each of the element that gets displayed on the HTML page has a corresponding Component(signified by wickert:id tag) in the corresponding page class. There are quite a few out of the box components provided by Wicket eg Button, DropDownChoice etc. Each of the components provided by Wicket has the same set of behaviours as those available on the HTML scripting side. By this approach you can say in java itself what kind of behaviour you want from the Component rather than writing JavaScript for the rendered HTML markup eg if you have a Button and you want to do something on the onSubmit then there is a method onSubmit that you can override and perform your set of actions. Now after creating them in the page class you must add them to the page by calling the add method of the page base class.

The page that you have created is part of a WebApplication. This web application should be implemented by extending the WebApplication class. The WebApplication class has methods that you can override for your custom behavior. The getHomePage method returns a page object that acts as the welcome page of your application.

In case your application is not a hello world application you will be required to maintain sessions. The session can be implemented by extending the  WebSession class. You can create your custom sessions that can hold different kinds of objects. You application class should then override the newSession method to return your custom sessions.

After creating all the pages, application and session classes you must configure the WicketFilter and your application class in your Web.xml

Testability and Spring integration:

Nothing gets done in Agile unless you can unit test it. The wicket package also provides support for testing of the UI components. The custom web application class that you wrote for your application can be tested using the WicketTester or the MockWebApplication class. Create an instance of this class and set the Webapplication argument and you are ready to test your application. This mock application  class returns MockRequests  using DummyApplication mock object that can be used to test your sessions and page classes.

But there are some down sides also. It does not seamlessly integrate with Spring. You must download the wicket-spring and wicket-spring-annot to integrate it with spring. More over there are some compatibility issues that I found. I tried to use spring 2.5 with Wicket 1.4 but was unsuccessful in that. Then I tried to use the 1.3.7 version of wicket and it worked!

Bottom Line:

The Apache wicket package is quite simple and has quite flat learning curve for a java developer. Most importantly it separates the concerns of a web designer and a developer. They both can work on separate components while taking care of the same things.

Wicket also provides a whole bunch of Components and lots of Ajax support. But at the same time I had a hard time configuring the behaviours of some of the components like DropDownChoice. Also you have to take extra care to keep things Serializable in your page and session classes. You can avoid this restriction but then you have to do some additional work like using  LoadableDetachableModel.

A better aspect of Wicket is that it facilitates test driven development approach for UI components. It can be integrated with  spring and guice injectors. Quckstarts are also available through maven archetypes.

Resources:

Apache Wicket

Wicket Examples

Example Wicket Project

Advertisements

6 Comments »

  1. […] This post was mentioned on Twitter by shivie. shivie said: Apache Wicket for GUI playground: An introduction http://digs.by/b5RTdz […]

    Pingback by Tweets that mention Apache Wicket for GUI playground | The road so far…. -- Topsy.com — May 9, 2010 @ 2:39 am

  2. Im curious what problems you have with wicket 1.4 and spring, we and many other people use spring 2.5 or 3 with the 1.4 series of wicket and it works perfectly. You might want to try on of the jWeekend legup maven archetypes (http://jweekend.com/dev/LegUp) for examples on how to get wicket and spring working correctly.

    Richard

    Comment by Richard Wilkinson — May 9, 2010 @ 9:43 pm

    • I think the issues that I faced were related to compatability, as the wicket-spring package was of 1.3.7 version while wicket was of 1.4. But thanks for the legup archetypes I will give them a shot. It looks like most of the dependencies have been taken care off.

      Comment by Rahul Sharma — May 10, 2010 @ 10:02 pm

    • I’ve not come across any issues with using Spring 3 and Wicket 1.4. We have also managed to use Wicket 1.3 and Spring 2.5 with no issues. I think some users do not realise the subtle configuration changes required when integrating Spring with Wicket e.g. web.xml.

      As already suggested, check out the LegUp artifact which should get you up and running.

      Comment by Joe — November 16, 2010 @ 4:07 am

  3. Nice write up. Are you familiar with GWT? I find them to be pretty similar, but I think wicket is better, but GWT has more momentum because it has Google behind it. The better technology Wicket, is going to lose because it doesn’t have enough clout.

    Comment by James — May 10, 2010 @ 7:54 pm

  4. I agree with most parts of your post!I think that Wicket’s strength is its simplicity and its architecture.Although it may not be as powerful as other web frameworks like spring I believe it enables you to create really good web apps.

    Comment by nikos lianeris — May 10, 2010 @ 8:12 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: