Wicket: Full guide for JDeveloper 11g


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.

Creating a new web project in JDeveloper

Creating a new web project in JDeveloper

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.

Project tab of JDeveloper

Project tab of JDeveloper

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.

Create a new class in JDeveloper

Create a new class in JDeveloper

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.

Accessing web.xml through the Projects tab

Accessing web.xml through the Projects tab

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.

DD in the XML editor of JDeveloper

DD in the XML editor of JDeveloper

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….

Creating an HTML file in JDeveloper

Creating an HTML file in JDeveloper

Expand the classes folder and double-click on pages.

Bundling the HTML page together with the class file

Bundling the HTML page together with the class file

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.

Debugging a wicket page is trivial

Debugging a wicket page is trivial

References

6 Responses to Wicket: Full guide for JDeveloper 11g

  1. A.B. Cade says:

    Thanks for the nice article.
    Is it possible to do the same in jdev 10 and deploy it to OC4J ?
    if so what changes should be made ?

    Thanks
    AB

  2. Paul says:

    Hi Niko,

    I tried this using Jdeveloper 10.1.3.4, and wicket 1.3.5.
    I deployed to an .ear file which I deployed to Oracle Application Server 10.1.3.4.

    When I try to run the application, I get
    “403 Forbidden Directory browsing not allowed”.

    I’m hoping it is something simple — do you have any ideas?

    The .ear file has the following entries:
    META-INF/application.xml
    webapp.war

    webapp.war has the following:
    WEB-INF/classes/pages/Hello.class
    WEB-INF/classes/pages/Hello.html
    WEB-INF/classes/wicketfun/MyApplication.class
    WEB-INF/lib/slf4j-api-1.5.6.jar
    WEB-INF/lib/slf4j-simple-1.5.6.jar
    WEB-INF/lib/wicket-1.3.5.jar
    WEB-INF/web.xml

  3. A.B. Cade says:

    Hi Paul,
    I used wicket with jdev 10.1.3.1 but it worked only when I used servlets instead of filters in the web.xml file.
    Otherwise I got the same message as you had …

    AB

  4. Seth says:

    As A.B. Cade states you have to use Servlets rather than Filters

    WicketApplication
    org.apache.wicket.protocol.http.WicketServlet

    applicationClassName
    wicketfun.MyApplication

    WicketApplication
    /*

  5. I consider this specific blog post , “Wicket: Full guide for JDeveloper 11g | Nikos’ Java blog”, particularly pleasurable plus the post was in fact a remarkable read. Thanks for your time,Francesco

  6. Mariella Bella says:

    Well I think you needed to be more specific about the application server configuration. Since you drafted this guideline referring to Jdeveloper, maybe you should have mentioned that when you deploy into the WebLogic instance, your html files will be overwritten causing an exception in Wicket. This guide is not useful unless you specify how to deploy into WebLogic integrated instance.

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: