Share on Google+Share on Google+

Echo Message example in Wicket

In previous section of Wicket tutorials we have been well aware with the way how we can create an application in Wicket framework.

Echo Message example in Wicket


In previous section of Wicket tutorials we have been well aware with the way how we can create an application in Wicket framework. Here is the simple example to display message in  Wicket.

 This example of displaying message in Wicket we have used following three file which create a simple message displaying example. These files are as follows:

  3. Echo.html

In this example of Echo message we have created Echo class by extending WebPage and here we have defined three properties for representing three fields of "firstname", "lastname" and "message". For setting properties values we have created their setters and getters method. According to properties PropertyModels are created and then further these models are added to form with the use TextField. Here is the full example code of :-

package com.roseindia.wicket;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;

public class Echo extends WebPage

 private String message = "type your message here";
 private String firstname = "first name";
 private String lastname  = "last name";

  public Echo()
  PropertyModel messageModel = new 
(this, "message");
  PropertyModel firstNameModel = new 
PropertyModel(this, "firstname");
  PropertyModel lastNameModel = new
PropertyModel(this, "lastname");
  add(new Label("msg", messageModel));
  add(new Label("fname", firstNameModel));
    add(new Label("lname", lastNameModel));
  Form form = new Form("form");
  form.add(new TextField("firstInput", firstNameModel));
  form.add(new TextField("lastInput", lastNameModel));
  form.add(new TextField("msgInput", messageModel));
  public String getMessage()
  return message;
  public void setMessage(String message)
  this.message = message;
  public String getFirstname() {
  return firstname;

  public String getLastname() {
 return lastname;
  public void setFirstname(String firstname) {
  this.firstname = firstname;
  public void setLastname(String lastname) {
  this.lastname = lastname;

This Echo class will be called via the EchoApplication and this EchoApplication extends WebApplication. Here is the example code of as follows:

package com.roseindia.wicket;
import org.apache.wicket.protocol.http.WebApplication;

public class EchoApplication extends WebApplication
  public EchoApplication()
  {   }
  public Class getHomePage()
  return Echo.class;


  <title>Wicket Examples - echo</title>
  <form wicket:id="form">
  <input type="text" wicket:id="firstInput" value="" size="20" />

  <input type="text" wicket:id="lastInput" value="" size="20" />

  <input type="text" wicket:id="msgInput" value="" size="50" />

  <input type="submit" value="set message" />
 First Name:
  <span wicket:id=
"fname" id="fname">First name here</span>
 Last  Name:
  <span wicket:id=
"lname" id="lname">Last name here</span>
 Messages :
  <span wicket:id="msg" id="msg">Message goes here</span>

To run this application successfully one more thing we need to do is to make entry of EchoApplication in XML file web.xml. Following are the few lines code to do filter mapping of EchoApplication in web.xml 


To run this example start your web server and type following URL into browser:


Download Source code



Posted on: October 6, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Echo Message example in Wicket  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
Surya Prabha
April 18, 2012
Values not displaying when running this tutorial

Hi, ran this tutorial and got the form but when clicked on set Message the values given in the input fields are not displayed instead the default values are displayed