HTML and Java: Two Sides of the Same Wicket Coin

Each web page in Wicket is like a coin. It has two sides -- a Java class and an HTML file.

  1. Setting Up the Coin: HelloWorldApplication.java. The application object creates the application that contains the web pages. The application object is a Java class. The absolute minimum content of the application object is the definition of the home page. The home page is the first web page displayed by the application object.

    Here the compiled HelloWorld.class web page is set as the home page:

    getPages().setHomePage(HelloWorld.class);

    The web page consists of two sides -- the Java component (the back or tails side) and its HTML rendering (the front or heads side). Importantly, since they are two sides of the same coin, the two sides have the same name and are stored in the same folder structure. Normally, this means that they are stored in the same package. So, in this case, the two sides are called HelloWorld.java and HelloWorld.html and are stored together in the same package.

  2. Tails: HelloWorld.java. Here a Label component is created:

    add(new Label("message", "Hello World!"));

    There are two parameters: the component identifier ("message") and the content that the Label component should render ("Hello World!").

  3. Heads: HelloWorld.html. A Java component is used in an HTML file:

    <span wicket:id="message">Message goes here</span>

    The <span> element has one attribute, in the wicket namespace: the identifier ("id") which is defined as "message". Note that the Wicket identifier in the HTML file must match the component identifier in the Java component. The "Message goes here" text is a placeholder. You could write anything you like there -- it will be replaced by the Java component.

  4. Flipping the Coin. A web.xml file specifies the Wicket servlet wicket.protocol.http.WicketServlet that handles requests for the application object. A server, such as Tomcat or Jetty, is needed in order to deploy the application.

To see all of the above in practice, within the context of the two Java classes and HTML file that make up the "Hello World" application, use yesterday's blog entry to set everything up in NetBeans IDE. Alternatively, use another IDE. All Wicket applications are based on the above principles -- except that most Wicket applications have more than one coin. If you have enough coins, you can create a really rich application...

Comments:

does this page uses wicket application?

Posted by guest on May 02, 2006 at 07:14 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
24
25
26
27
28
29
30
   
       
Today