praveenkolla
praveenkolla

Reputation: 11

I am not able to run my apache wicket sample program

I am very new to java wicket. I don't understand how to run this code. My wicket program follows the structure below. My problem is that I am not able to run this. I am getting a 404 error.

This is my wicket code to get a hello world message.

HelloWorld.html:

<html xmlns:wicket> 
    <title>Hello World</title>
 </head>
 <body>
     <span wicket:id="message" id="message">Message goes here</span>
 </body>
 </html>
 </html>

HelloWorld.java:

package com.sensiple.wicket;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;

public class HelloWorld extends WebPage {

    public HelloWorld() {
        add(new Label("message", "Hello World!"));
    }
}

This class is returning hello world which is to be printed in HelloWorld.html

HelloWorldApplication.java:

package com.sensiple.wicket;

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

public class HelloWorldApplication extends WebApplication {

//what is the need of this constructor, need of this class in this program
    public HelloWorldApplication() {
    }

I need to know what is the use of getHomePage-method too, as I am not getting what is the use of one more class here which returns return type as HelloWorld. Hardly I am not able to run this code. I went through many resources which didn't help.

    public Class<HelloWorld> getHomePage() {
        System.out.println("initialized!!!!");
        return HelloWorld.class;
    }
}

Upvotes: 0

Views: 482

Answers (2)

papkass
papkass

Reputation: 1289

Try using this html:

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
 <head> 
    <title>Hello World</title>
 </head>
 <body>
     <span wicket:id="message"></span>
 </body>
</html>

When your application is running, just call http://localhost:8080 (unless you changed the port) and wicket should redirect you to your HelloWorld page

Upvotes: 0

Nicktar
Nicktar

Reputation: 5575

To start answering your many questions:

  1. Your program is most likely returning a 404 due to the malformed HTML in your HelloWord.html. Wicket required valis XHTML to work with.

  2. The original signature of getHomePage() is public abstract Class<? extends Page> getHomePage(). You can implement it as you did as it fullfills the contract. The method returns the class that is used to render the homepage of your web application. That's the page that is shown at the base-url of your application without any mountpoints or parameters.

  3. You don't need the default constructor to your WebApplication but you can implement one to do some of the initialisations needed for your application. It's run once at the start of your application (or in most cases your container).

Upvotes: 1

Related Questions