Until version 1.5.x attaching an Ajax event behavior to a component would lead to addition of an inline attribute to the markup of this component. For example the produced markup for an AjaxLink is similar to:
The benefit is that the event registrations for all elements are done in one place - the page header and your markup elements are not cluttered with extra attributes. Also the generated code for the event registration is much shorter than the one produced in the earlier versions.
jQuery as backing library</h1>
The previous implementations of wicket-ajax.js and wicket-event.js were home baked solutions which worked well but also suffered from the differences in the browsers. Often users complained that some functionality doesn't work on particular version of particular browser. That's why the Wicket team chose to use JQuery to deal with browser inconsistencies and leave us to do our business logic.
Ajax request attributes
The main change in the Java code is the introduction of AjaxRequestAttributes in Ajax behaviors API.
AjaxRequestAttributes can be used to configure how exactly the Ajax call should be executed and how its response should be processed. To do this use:
Ajax call listeners
To register an AjaxCallListener do something like:
Global Ajax call listeners
IAjaxCallListener's can be used to listen for the lifecycle of an Ajax call for a specific component. If the user application needs to listen for all Ajax calls then it may subscribe to the following topics:
Those replaces the old Wicket.Ajax.(registerPreCallHandler|registerPostCallHandler|registerFailureHandler) methods and uses publish/subscribe mechanism.
All global listeners receive the same arguments as the respective IAjaxCallListener handler plus jQuery.Event that is passed by the PubSub system.
At Martin Grigorov's GitHub repository you may find a simple demo application that shows some of the new features.
The application provides a custom AjaxButton (HandlebarsButton) that uses:
- org.apache.wicket.ajax.attributes.AjaxRequestAttributes#setWicketAjaxResponse(false) - tells Wicket.Ajax to not try to process the returned Ajax response. The response is custom JSON which will be processed by a custom success handler
- usage of plain Strings with the function bodies for the precondition, before and complete handlers - Wicket will wrap them in JsonFunction for you
- shows how to suppress the execution of AjaxRequestHandler - there is no need of it since we return custom JSON response
More complete documentation may be found at the Wiki. Feel free to contribute to make it better. Just create an account and edit it!