Skip to main content

Get to love web development

Posted by gfx on August 10, 2005 at 9:49 PM PDT

I like rich applications. I love to develop rich applications. I foster rich applications development. And guess what? I find web development boring and damn annoying. Asides from being a student and an intern at Sun, I'm also a journalist from a french computing magazine. I spent the last 5 years learning, discovering and teaching dozens of technologies, and there were a lot web oriented ones among them. Even if I'm perfectly aware of the appeal those technologies can have for companies, I find them boring and overly complicated. I even feel too dumb to use them sometimes.

Last week I wrote an article about Wicket and I spent some time discovering and taming it. And I have to confess this: I love it. First Wicket benefits from a great web sites with nice examples and a good documentation, even if some examples do not work with the latest 1.1 betas. Wicket is a light, easy to use framework. Heck, I don't even want to call it a "framework", let's leave that to other mind boggling beasts. Let's call it a candy bar. Yeah, that's right, Wicket is not a framework, it's a candy bar. And everybody loves candy bars (and if you don't, just pretend you do :).

So, not only did the authors tried to bring us a powerful and easy to use web library, they indeed reached their goal. Can you picture a Java web framework candy bar with no XML configuration file? Well, apart from the necessary web.xml that is. Can you picture a web library with a Swing-alike API? Can you imagine a web library fostering the separation between logic and presentation in a clean way? That's what Wicket is!

Oh and Wicket is easy to install and available under the Apache license. But let's take a look at an actual Wicket application. The name application is not innocent since you do create a WebApplication class. You declare your applications in the web.xml:


  Hello World Wicket
 
    HelloWorldApplication
    wicket.protocol.http.WicketServlet
   
      applicationClassName
      HelloWorldApplication
   

    1
 


 
    HelloWorldApplication
    /helloworld/*
 

As you can see this is very straightforward, especially if you are accustomed to JSP/J2EE development. Your next step is to implement the application itself:
import wicket.protocol.http.WebApplication;

public class HelloWorldApplication extends WebApplication {
  public HelloWorldApplication() {
    getPages().setHomePage(HelloWorldPage.class);
  }
}

This application is very simple but you can interact with many settings. In this case, we simply set the home page. As for the application, a page is just a regular Java class, in this case extending WebPage. This is were Wicket becomes really interesting, for a page is not only a Java class but also an HTML file. The HTML page will contain the presentation layer and the Java class the (business) logic layer. Here is for instance HelloWorldPage.html:

 
    Hello World Wicket
 
 
    Message placeholder
 

On the contrary to other solutions, Wicket's presentation layer does not contain any logic. No code. Just plain, old XHTML. Or to please Java EE guys with a new acronym, POX. The idea here is to identify the elements your code will interact with by giving them a wicket:id attribute. The beauty of this is you can edit the pages in any weird WYSIWYG without breaking the code! Designers can do their job, programmers can do their job and they don't need to stomp on each other for that. Finally, here is the logic:
import wicket.markup.html.WebPage;
import wicket.markup.html.basic.Label;

public class HelloWorldPage extends WebPage {
  public HelloWorldPage() {
    add(new Label("message", "Hello World !"));
  }
}

Very easy, isn't it? You just create a new label, mapped to the element called message, giving it the value Hello World !. You're done, you just need to open http://localhost:8080/helloworld and it works!

This example is really simple but it should give you a good idea of how Wicket works on the lower level. Wicket provides a lot of other features. For instance, it manages components state on the server side and makes it really easy to handle forms. As you can bind POJOs to components as their model, it is very easy to handle users input. The chat, or "shout box", example from Wicket examples is an impressive example of clarity.

I really urge you to go to Wicket official web site to read the various tutorials and introductions. You won't regret it.

Related Topics >>