Hello World

In this example, we’ll display the famous text “Hello,World!” in a browser and have the text delivered to us by Wicket.

In a Wicket application, each page consists of an HTML markup file and an associated
Java class (Both files should reside in the same package folder).  In our case will create one HTML -Helloworld.html and one java - Helloworld.java

First Create wicket project using quick start.

        <title>Hello World</title>
        <span wicket:id="message">dynamic message will be replace here </span>
package com.javaassist;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.request.mapper.parameter.PageParameters;
public class HelloWorld extends WebPage {
 private static final long serialVersionUID = 1L;
    public HelloWorld(final PageParameters parameters) {
        add(new Label("message", "Hello World, java-assist"));
we’ll add a label component (org.apache.wicket.markup.html.basic.Label) to the page to display the dynamic text.

Application object for web application.  

WebApplication returns a “HelloWorld.class” as the default home page, when Wicket see this “HelloWorld.class“, it know the mark up “html” page should be “HelloWorld.html“, and it should be able to find at the same package directory.

package com.javaassist;

import org.apache.wicket.protocol.http.WebApplication;

public class WicketApplication extends WebApplication

 public Class<HelloWorld> getHomePage()
  return HelloWorld.class;
Define Application object in wicket filter to make application work.
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"




Project Structure

Test the app
Run the Jetty server and use "http://localhost:8080/" url

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...