Apache Wicket

Apache Wicket is a lightweight component-based web application framework for Java. This document explains how to write the first program in Apache Wicket and run it.
  • Prerequisite

    For Apache Wicket to run, first you will need to install JDK – Java Development Kit. And for building the application you will need to install Maven. To run an application you need any web server or application server. Here we are using JBoss Application Server. The Apache Wicket version used is Wicket-6.15.0 and Eclipse version used is Eclipse Juno v4.2.
  • Now Run the application with JBoss Application Server. The Application will display a message Hello World on the screen.
  • Apache Wicket Hello World Program

    Once the JDK and Maven setup is done, create apache-wicket directory in C drive. Go to command prompt, change the directory to C:\apache-wicket and run below code.
            mvn archetype:generate -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId=wicket-archetype-quickstart -DarchetypeVersion=6.15.0 -DgroupId=com.example -DartifactId=myproject -DarchetypeRepository=https://repository.apache.org/ -DinteractiveMode=false
            
    Apache Wicket Build Start
    The above line will create a project structure in the directory C:\apache-wicket. Once executed successfully BUILD SUCCESS message will be displayed on the console.
    Apache Wicket Build Success
    Now open Eclipse IDE. Give the folder path C:\apache-wicket in eclipse workspace.
    Apache Wicket Open Workspace
    Import the project created with Maven into eclipse workspace. Use eclipse menu File -> Import.. to import the source code and available for editing.
    Apache Wicket Import Project
    Browse the folder in root directory C:\apache-wicket. The project named myproject will be listed in Projects, showing pom.xml maven build file. Click the Finish button to complete the import.
    Apache Wicket Import Select Root
    The project structure will be created in eclipse, Project Explorer.
    Apache Wicket Project Structure
    Now write code for first apache wicket program inside package com.example.
    HelloWorld.java
            package com.example;
    
            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!"));
                }
            }
            
    HelloWorld.html
        
             
                   
                   Apache Wicket Hello World
             
             
                   <span>Message goes here</span>
             
        
    

    Now edit code for below files.

    WicketApplication.java
            package com.example;
    
            import org.apache.wicket.markup.html.WebPage;
            import org.apache.wicket.protocol.http.WebApplication;
    
            public class WicketApplication extends WebApplication
            {
                /**
                * @see org.apache.wicket.Application#getHomePage()
                */
                @Override
                public Class&amp;amp;lt;? extends WebPage&amp;amp;gt; getHomePage()
                {
                    return HelloWorld.class;
                }
            }
            
    Web.xml
    
    
       ApacheWicketExample
       
          wicket.myproject
          org.apache.wicket.protocol.http.WicketFilter
          
             applicationClassName
             com.example.WicketApplication
          
       
       
          wicket.myproject
          /*
       
    
    
    Now Run the application with JBoss Application Server. The Application will display a message Hello World on the screen.

    Apache Wicket Application Run

Find the Source Code on GitHub: Apache Wicket.

 


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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.