AJAX in Apache Wicket

DZone 's Guide to

AJAX in Apache Wicket

In this article, I discuss some of the advantages of using AJAX in Apache Wicket. Read on to learn more.

· Web Dev Zone ·
Free Resource

First, a bit about JavaScript: JavaScript (aka Mocha, aka LiveScript, and many other names) is a client-side (i.e. the browser) scripting language. That means it takes the burden off of processing data from your server thus making it more responsive.

Just as there are many advantages of using JavaScript (such as speed, simplicity, etc.) there are downsides as well: it is frequently turned off in browsers because of security concerns, it can be easily exploited, etc.

AJAX (Asynchronous JavaScript + XML) is based on JavaScript with some other technologies like HTML and CSS and is used to dynamically update parts of the UI without having to reload the page.

While AJAX can be used with many Java frameworks (Spring MVC, Struts, JFS, etc.), it is very easy to use AJAX with Apache Wicket. You don’t even need to write a single line of JavaScript as Wicket has a bunch of AJAX-enabled components.

Here are some advantages of using AJAX in Wicket :

  1. As a Java developer, you can focus on pure Java without needing to learn JavaScript.
  2. The are many built-in AJAX components, also AJAX behavior is encapsulated in Wicket's reusable components.
  3. It is easy to replace components on the fly.
  4. There are faster, more responsive user interfaces, as AJAX requests do not completely refresh the whole page.
  5. It has an excellent debugging utility for debugging AJAX calls.

So, let’s see how much easier it is to use AJAX with Wicket than the traditional approach. Let's see how to submit a form without writing a single line of JavaScript. 

You just need to add a button that can be used to submit the form via AJAX:

form.add(new AjaxButton(“ajax-button”, form)
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
// repaint the feedback panel so that it is hidden

protected void onError(AjaxRequestTarget target, Form<?> form)
// repaint the feedback panel so errors are shown

And that’s all. There is no JavaScript in HTML (i.e. markup file) of your Wicket application!

Note: the above piece of code is from the Wicket Library examples and a complete example can be found here.

ajax, apache wicket, framework, java, javascript

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}