Jump to content

Apache Wicket

From Alfawiki
Apache Wicket
Company typeOpen source software
IndustrySoftware framework
FoundedApril 2004; 22 years ago (2004-04)
FounderJonathan Locke
Headquarters
United States
ProductsWeb application framework
Websitewicket.apache.org

Apache Wicket, commonly referred to as Wicket, is a Java-based web application framework that emphasizes a component-oriented approach, akin to JavaServer Faces and Tapestry. Developed by Jonathan Locke in April 2004, its initial 1.0 release appeared in June 2005. By June 2007, it had advanced to become a top-level project under the Apache umbrella.

Rationale

Conventional model-view-controller (MVC) frameworks typically process entire requests and pages by linking requests to controller methods that generate responses through populating views with model data. While this streamlines control flow, it can restrict the reusability of controller code.

In contrast, Wicket adopts the principles of stateful GUI frameworks such as Swing. Its applications consist of hierarchical components that employ listener delegates to manage HTTP requests in a manner comparable to handling GUI events. This places Wicket within the category of component-based frameworks.

Design

Wicket utilizes straightforward XHTML templates, promoting a clean division between presentation layers and business logic, and enabling editing via standard WYSIWYG editors. Each component corresponds to a specifically named XHTML element and is responsible for rendering that element in the output. The page serves as the highest-level component linked with a single XHTML template. Components can be organized into reusable panels that facilitate sharing across multiple pages.

Every component maintains its own model encapsulating its state. These models are treated as opaque entities, automatically serialized and preserved across requests. For more sophisticated scenarios, models can be detachable, managing their persistence hooks during each request cycle. Wicket does not impose any particular persistence or ORM framework; applications frequently integrate with tools like Hibernate, EJBs, or plain old Java objects (POJOs) serving as models.

State management on the server side is comprehensively handled by Wicket without direct manipulation of HttpSession objects. State data is linked to components, each encompassing nested structures of stateful components backed by POJOs.

Wicket prioritizes simplicity by eliminating configuration files altogether and providing a consistent class library centered on its component architecture.

Example

A basic Hello World example built with Wicket involves four essential files:

HelloWorld.html
The XHTML template defining the markup.

<syntaxhighlight lang="xml"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"

     xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
     xml:lang="en" lang="en">

<body>

   Message goes here

</body> </html> </syntaxhighlight>

HelloWorld.java
The page component linked to the template, which inserts a Label component with the identifier "message".

<syntaxhighlight lang="java"> package org.wikipedia.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!"));
   }

} </syntaxhighlight>

HelloWorldApplication.java
The primary application class directing homepage requests to the HelloWorld page component.

<syntaxhighlight lang="java"> package org.wikipedia.wicket;

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

public class HelloWorldApplication extends WebApplication {

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

} </syntaxhighlight>

web.xml
The servlet deployment descriptor configuring Wicket as the default handler and initializing HelloWorldApplication upon startup.

<syntaxhighlight lang="xml"> <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                            http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
        id="WebApp_ID" version="2.5">
   <display-name>Wicket Example</display-name>
   <filter>
       <filter-name>HelloWorldApplication</filter-name>
       <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
       <init-param>
           <param-name>applicationClassName</param-name>
           <param-value>org.wikipedia.wicket.HelloWorldApplication</param-value>
       </init-param>
   </filter>
   <filter-mapping>
       <filter-name>HelloWorldApplication</filter-name>
       <url-pattern>/*</url-pattern>
   </filter-mapping>

</web-app> </syntaxhighlight>

Components

Built-in elements include fundamental components like forms, hyperlinks, and repeaters.

Releases

Apache Wicket Versions
Series Overview Most recent version Release date of latest version
Template:Version Transitioned from Javax to Jakarta APIs with updated dependencies aligned to Spring Framework 6, requiring a minimum of Java 17 and supporting up to Java 21. ByteBuddy has replaced CGLib. 10.0.0 2024-03-11
Template:Version Requires at least Java 11, shifted testing from JUnit 4 to JUnit 5, added compatibility for Java 12 and 13, redesigned page and data storage mechanisms. 9.16.0 2023-11-23
Template:Version Java 8 is the minimum supported version, introduced Lambda support, mandates Servlet API 3.1, enhanced date processing capabilities. 8.14.0 2022-01-29
Template:Version Supports Java 7 or higher, implemented cross-site request forgery protection, added inline image functionality, includes nearly 300 enhancements and bug fixes. 7.18.0 2021-04-02
Template:Version Requires Java 6 minimum, integrated jQuery, improved AJAX features, refined event registration system, optimized for handling large datasets, introduced client-side dependency management. 6.30.0 2018-12-05
Template:Version Introduced various feature enhancements. 1.5.16 2016-08-05
Template:Version Supported on Java 5 platform as minimum requirement. 1.4.23 2014-02-06

See also

References

External links