Table of Contents
HelloWorld demonstrates the basic structure of a web application in Wicket. A Label component is used to display a message on the home page for the application.
In all the Wicket examples, you have to put all files in the same package directory. This means putting the markup files and the java files next to one another. It is possible to alter this behavior, but that is beyond the scope of this example. The only exception is the obligatory web.xml file which should reside in the WEB-INF/ directory of your web application root folder.
If you wish to start building this example, you may want to take a look at the Wicket Quickstart project, which provides a quick way of getting up and running without having to figure things out yourself. The Quickstart project contains the necessary build files (Ant and Maven), libraries, minimal set of Java and markup files and an embedded Jetty server to run your application without having to go through the whole build-deploy cycle.
Each Wicket application is defined by an Application object. This object defines what the home page is, and allows for some configuration.
Here you can see that we define
wicket.examples.helloworld.HelloWorld to be
our home page. When the base URL of our application is requested, the markup
rendered by the HelloWorld page is returned.
The Label is constructed using two parameters:
The first parameter is the component identifier, which Wicket uses to identify
Label component in your HTML markup. The second parameter is the message
Label should render.
The HTML file that defines our Hello World functionality is as follows:
In this file, you see two elements that need some attention:
the component declaration
Message goes here
The component declaration consists of the Wicket identifier
wicket:id and the
message. The component identifier should be the same as
the name of the component you defined in your
WebPage. The text between
<span> tags is removed when the component renders its message. The final
content of the component is determined by your Java code.
In order to deploy our HelloWorld program, we need to make our application known to the application server by means of the web.xml file.
In this definition you see the Wicket filter defined, which handles all requests. In order to let Wicket know which application is available, only the applicationClassName filter parameter is needed.
Ready to deploy
That’s it. No more configuration necessary! All you need to do now is to
deploy the web application into your favorite application server. Point your
browser to the url:
servername and warfilename to the appropriate values, such as
As you can see: no superfluous XML configuration files are needed to enable a Wicket application. Only the markup (HTML) files, the Java class files and the required web.xml were needed to create this application.