This article presents how a complete Wicket project is built from ground-up in JDeveloper 11g.
Go through steps 1-3 to setup a wicket project.
Go through step 4 to create a page.
Go through steps 5-7 to deploy, test and debug the page.
1. Create a web project
File → New… → General → Projects → Web Project → OK.
In the wizard click next, give the project a name, e.g. WicketFun and click Next until the option Finish appears. The project should now appear in the Projects tab.
2. Concentrate all jars
Download wicket from wicket.apache.org → Releases → Wicket 1.4 → Select an appropriate mirror and get apache-wicket-1.4-m3.zip
Download simple logging facade from slf4j.org → Download → slf4j-1.5.2.zip
Create a folder and place inside the following:
- 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
Add these jars to the classpath by right clicking on the project → Project Properties… → Libraries and Classpath → Add JAR/Directory…
These three are all you need for a wicket application. However, there are some extra interfaces of great interest: The date-time functionality (wicket-datetime-1.4-m2.jar) and the integration with Spring (wicket-spring-1.4-m2.jar).
3. Make the WebApplication
Wicket’s starting point is a WebApplication.
Right click on project → New → General → Simple Files → Java Class → Provide the name MyApplication, declare that it extends WebApplication and click OK.
This class should implement the getHomePage() method.
package wicketfun;
import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
public class MyApplication extends WebApplication {
public Class<? extends Page> getHomePage() {
return null;
}
}
For the time being just let it return null.
In the Projects tab double-click on web.xml → XML and paste the following elements
<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>wicketfun.MyApplication</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>WicketApplication</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Here’s how web.xml should look.
4. Make a page
Let’s call it Hello. We should create Hello.html and Hello.java! As simple as it gets.
Right click on project → New → General → Simple Files → Java Class → Provide the name Hello, the package pages, make it extend WebPage and click OK.
This class should provide a default no-arg constructor.
package pages;
import org.apache.wicket.markup.html.WebPage;
public class Hello extends WebPage {
public Hello() {
// wicket action here
}
}
To make the classes compile right click the project and select Rebuild.
After a successful compilation, right click on project → New… → Web Tier → HTML → HTML Page → Provide the name Hello and click on Browse….
Expand the classes folder and double-click on pages.
In this way the html file will be bundled in the same directory with the class file. Just press OK to complete.
Let’s make this page simply display the current year.
<html>
<body>
The year is: <span wicket:id="year"></span>
</body>
</html>
Back to the class for some action.
package pages;
import java.util.Calendar;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
public class Hello extends WebPage {
public Hello() {
Integer year = Calendar.getInstance().get(Calendar.YEAR);
add(new Label("year", year.toString()));
}
}
5. Declare the home page
Every time you create a page you’d like to test it.
Just go to the getHomePage() of your WebApplication and make it return your page.
package wicketfun;
import pages.Hello;
import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
public class MyApplication extends WebApplication {
public Class<? extends Page> getHomePage() {
return Hello.class;
}
}
In this way when the application context is called on the browser, e.g. http://localhost:8080/wicket, this page will be called.
6. Run the page
Deploy the application to your favorite server, for example JBoss, GlassFish or the bundled Weblogic, to see it in action.
7. Debug the page
Wicket keeps the java code totally independent from the HTML markup. So debugging is easy.
Make a breakpoint by clicking on the left of the desired line.






























