JP

Gettting started Apache Wicket

update: 6 Mar 2018

Introduction

Apache Wicket is a component web framework written in Java. This is knew as the component-oriented.

Ready Apache Wicket

You first need to ready maven, you enter in command line after access to Wicket home page. Become like following my case:


        mvn archetype:generate -DarchetypeGroupId=org.apache.wicket -DarchetypeArtifactId=wicket-archetype-quickstart -DarchetypeVersion=7.10.0 -DgroupId=com.juke99 -DartifactId=myproject -DarchetypeRepository=https://repository.apache.org/ -DinteractiveMode=false
      

Hello World

Tentatively, let's create easy example. Now, you write the following sentence in web.xml.


        <filter>
          <filter-name>HelloWorldApp</filter-name>
          <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
          <init-param>
          	<param-name>applicationClassName</param-name>
          	<param-value>com.juke99.HelloWorldApp</param-value>
          </init-param>
        </filter>

        <filter-mapping>
      		<filter-name>HelloWorldApp</filter-name>
      		<url-pattern>/hello/*</url-pattern>
      	</filter-mapping>
      

After writed this code, you create HelloWorld.java and HelloWorldApp.java into a package. And you need to create HelloWorld.html into same package which HelloWorld.java exist.
The following code is HelloWorld.java and HelloWorld.html and HelloWorldApp.java.

HelloWorld.java:


        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"));
          }
        }
      

HelloWorldApp.java:


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

        public class HelloWorldApp extends WebApplication {

          @Override public void init() {
            super.init();
          }

          @Override public Class getHomePage() {
            return HelloWorld.class;
          }
        }
      

HelloWorld.html:


        <h1 wicket:id="message">[text goes here]</h1>
      

After compiled in maven, You move in project directly, and enter mvn jetty:run in command line. You will show the following, entering http://localhost:8080/hello to URL on browser:

I'm going to do more detail thing of Wicket in next article.

Home