Wicket 1: Setup Wicket


This starts a series of articles about Wicket. Let’s start using this excellent framework.

Download

Go to wicket.apache.org → Releases → Wicket 1.4 → Select an appropriate mirror and get apache-wicket-1.4-m3.zip

Go to slf4j.org → Download → slf4j-1.5.2.zip

Collect the jars

Add the following jars to the classpath:

  • apache-wicket-1.4-m3\lib\wicket-1.4-m3.jar
  • slf4j-1.5.2\slf4j-simple-1.5.2.jar
  • slf4j-1.5.2\slf4j-api-1.5.2.jar

Configure web.xml

Just add the following to web.xml.

<filter>
   <filter-name>WicketApplication</filter-name>
   <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
   <init-param>
      <param-name>applicationClassName</param-name>
      <param-value>wicket.Home</param-value>
   </init-param>
</filter>
<filter-mapping>
   <filter-name>WicketApplication</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>

You should only focus on wicket.Home: the class you’ll write in the next step. Of course the package and name of the class is up to you.

Define the starting point

The web application is a class of type WebApplication.

public class Home extends WebApplication {

}

This class must implement a method that specifies the home page.

public class Home extends WebApplication {

   public Class getHomePage() {
      return Hello.class;
   }

}

Hello is the welcome page. It’s what appears on the browser if you call the application context, e.g. http://localhost:8080/wicket.

Start building your pages

Every page has an html file Hello.html and a java file Hello.java of type WebPage.

For example this is Hello.html,

<html>
   <body>
      <h1>Hello from Wicket!</h1>
   </body>
</html>

and this is Hello.java.

public class Hello extends WebPage {

}

That’s a minimal page. For normal pages, all the action happens in the no-arg constructor.

Deployment

The only requirement is that the html file is stored in the same directory with its associated class file. That’s all!

Advantages of Wicket

HTML files need no scriptlets, no JSTL, no custom tags, not even a single java statement. This makes development and maintenance enjoyable.

  1. Real separation of Java and HTML code.
  2. No additional XML configuration.
  3. Everything is done in Java.

Review

  • Every web application IS-A WebApplication.
  • Every page IS-A WebPage.
  • Every html file has an associated java file.

6 Responses to Wicket 1: Setup Wicket

  1. The maven archetype is even easier to get started with if you use Maven. Just click “quick start” from the Apache Wicket home page. You’ll be running Wicket in about 2 minutes.

  2. nikosjava says:

    Hi Mr. Locke, thank you for stopping by. Congratulations for creating Wicket!

  3. […] Niko’s java blog quick & easy Java tutorials « Wicket 1: Setup Wicket […]

  4. […] It’s trivial to create your pages without even a plugin. For setup information you may recall part 1. […]

  5. […] For setup information please recall part 1. […]

  6. mike says:

    I love Wicket🙂

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: