Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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)
{
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
// repaint the feedback panel so that it is hidden
target.add(feedback);
}

@Override
protected void onError(AjaxRequestTarget target, Form<?> form)
{
// repaint the feedback panel so errors are shown
target.add(feedback);
}
});

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.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
apache wicket ,ajax ,javascript ,java ,framework

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}