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 out burden of processing data from your server making it more responsive.
As there are advantages of using JavaScript as speed, simplicity etc. there are downsides as well like 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 like Spring MVC,Struts , JFS etc, it is very easy to use Ajax with wicket. You don’t even need to write a single line of JavaScript as Wicket has bunch of Ajax enabled components.
Here are advantages of Ajax in wicket :
- As a java developer you can focus on pure java without need to learn JavaScript.
- Many built-in AJAX components, also Ajax behavior encapsulated in wickets reusable components.
- It is easy to replace components on the fly.
- Faster, more responsive user interfaces, as Ajax requests do not completely refresh whole page.
- It has excellent debugging utility for debugging Ajax calls
So let’s see how easy it is to use Ajax with wicket than 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. No JavaScript in HTML i.e.markup file of your wicket application!!!
Note: above piece of code is from Wicket Library examples and complete example can be found here.