• Fat Cats Boardgame
  • Wicket UI Library
  • About Me

Java and Wicket web development thoughts, tutorials, and tips

roman@coderdreams.com
Coder DreamsCoder Dreams
  • Fat Cats Boardgame
  • Wicket UI Library
  • About Me

Five reasons you should use Apache Wicket

February 4, 2020 Posted by Roman Sery wicket No Comments

Apache Wicket is a java-based web development framework. I feel it doesn’t get as much attention as it deserves. I’ve been using Wicket professionally for real-world projects for the past 6 years and love it!

In this post, let’s look at five reasons why you should consider using it.

1. Simple state management

The development experience writing Wicket apps is very similar to desktop development. At times you can almost forget about the stateless nature of HTTP. This is because in Wicket the web page and all of it’s components (buttons, text fields, etc) are Java objects that maintain their own state. The state of the components gets serialized into the user’s session, and deserialized at the appropriate times.

In simpler terms, suppose you have a form with fields that a user would fill out and submit. In a Wicket app, this form, it’s fields, and the submit button are all components(Java objects) that are created and added to the web page. When the submit button is clicked:

  • We automatically have access to the user input, usually as fields of a POJO.
  • We don’t have to connect the HTTP POST request to the GET request.
  • We also do not need to think about populating the form fields with the submitted values. This is done through Models which are a core Wicket concept.

2. Standard HTML integration

HTML in Wicket doesn’t require any special tags unlike some other frameworks. In fact you can take any existing HTML and integrate it with your Wicket app with almost no changes. There is only one attribute that is needed to connect HTML tags to Wicket components: wicket:id Let’s look at an example:

<div wicket:id="userName">Roman</div>
add(new Label("userName", getUsername()));

The wicket:id “userName” is used to connect the HTML element with the Wicket component. The Wicket Label component will get the user name and render a div tag. It’s okay if this doesn’t totally make sense right now. It becomes second nature and intuitive when you start playing around with it.

Wicket components are first-class citizens and can encapsulate their own HTML markup/CSS/JS just like in some popular frameworks such as React. This allows us to create highly-reusable code.

3. No Javascript needed (mostly)

Okay obviously, you will end up writing JS code at some point. However the AJAX support provided by Wicket means you don’t need to write your own JS code for most common tasks. Behind the scenes, Wicket uses JQuery and automatically generates the JS code into the web page.

Let’s take a simple example of a page with a dropdown and various other components that depend on the selection of that dropdown. When the selection changes, we need to update these various other components on the page. This actually doesn’t require any Javascript code.

This makes Wicket ideal for building complex interfaces with convoluted business logic.

4. Event/messaging system

Wicket events are a way for components and pages to communicate with each other. Using this feature we can create very complex, yet decoupled, component structures. A component can broadcast a message without needing to know who will receive the message. When a component is interested in a particular type of message, it can simply register to be notified when that message is broadcast.

A component might broadcast a critical update event with payload to all other components on the page in this manner:

send(getPage(), Broadcast.BREADTH, new CriticalUpdate(target, payload));

And if some component is interested in receiving CriticalUpdate’s, it would register like this:

public void onEvent(IEvent<?> event) {
   if (event.getPayload() instanceof CriticalUpdate) {
      String msg = ((CriticalUpdate)event.getPayload());
      //do something with the msg
   }
}

5. Unit testing

The component/stateful nature of Wicket means that we can write unit tests for the front-end just like we would write them for the service layer, or our data access layer. Wicket provides helpful utilities to make writing unit tests simple.

Let’s take an example of a simple scenario that might not be so straight forward to test in other frameworks. We have a web page with a CRUD interface: a table with baby names and delete buttons. A form with a text field and button for adding new rows to the table.

We can write a test that will render the page, simulate a user filling out and submitting the form, ensuring the table is updated correctly, simulate the user pressing the delete button, and so on. This can all be accomplished using pure Java code and JUnit without resorting to Selenium, Puppeteer or similar libraries.

6. Fully open source

Ok I did say five reasons, but here’s a bonus: Wicket is fully open source and the code is designed to be easily extendable/customizable. Whenever you run into a scenario where the default behavior or functionality doesn’t quite meet your needs, it’s as simple as overriding a few methods, or extending a class to make it work exactly as you need!

Conclusion

I hope you’ve heard enough to give Wicket a try. If you’re curious to learn more:

  • Head over to the official site which contains great documentation
  • Take a look the example code which provides code for many common web dev scenarios.
No Comments
Share
3

About Roman Sery

I've been a software developer for over 10 years and still loving Java!

You also might be interested in

Creating secure encrypted links in Wicket with Apache Shiro

Nov 16, 2019

Quickly get started creating secure encrypted links in your Wicket application!

Launching LetsDefinitely.com – A dating website

Jul 28, 2020

Launching LetsDefinitely.com - A dating website

Self-contained Wicket Fragments

Oct 31, 2020

Create self-contained Fragments that don't need to duplicate markup

Categories

  • aws
  • customization
  • database
  • debugging
  • enum
  • java
  • models
  • performance
  • projects
  • react
  • software design
  • Spring
  • tool
  • Uncategorized
  • wicket

Recent Posts

  • Rent Day
  • Self-contained Wicket Fragments
  • Pros and cons of unit testing
  • Themeable React Monopoly board
  • Please dont use client-specific release branches

Recent Comments

  • TCI Express Thanks for sharing such insightful information. TCI Express truly stands out as the best air logistics company, offering fast, secure, and efficient air express and cold chain transportation services....

    Tracking down a bug in production Wicket application ·  March 25, 2025

  • Tom Error: A zip file cannot include itself Can you please correct the plugin part so it doesn't use the same folder as input?

    Deploying Spring Boot app to AWS Beanstalk with Nginx customization ·  September 3, 2021

  • Golfman: Reality always wins I've used both Wicket and front-end JS frameworks and, having worked extensively on both, I can tell you that "Speed of development" is definitely NOT with the JS frameworks. You basically end up...

    Five reasons you should use Apache Wicket ·  August 29, 2021

  • Kiriller Sorry can not agree with you, wicket might be a well built technical framework. But the advantages of using a front-end framework like react.js and vue.js can not be beaten by Wicket nowadays. - Speed...

    Five reasons you should use Apache Wicket ·  August 23, 2021

  • Bernd Lauert Sorry but i have to refute your claims with the following arguments: 1. the Wicket community may be small but it is also very responsive, you usually get a helpful answer from the core devs on the...

    Five reasons you should use Apache Wicket ·  July 1, 2021

Archives

  • May 2021
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019

Contact Me

Send Message
Prev Next