...
Code Block |
---|
getJavaScriptLibrarySettings().setBackingLibraryReference(AnotherVersionOfJQueryReference.class); |
AjaxRequestAttributes
Each Ajax behavior and component can use o.a.w.ajax.attributes.AjaxRequestAttributes to configure how exactly the Ajax call should be executed and how its response should be handled. To do this use:
AnyAjaxComponent/AnyAjaxBehavior.java:
Code Block |
---|
protected void updateAjaxAttributes(AjaxRequestAttributes attributes)
{
super.updateAjaxAttributes(AjaxRequestAttributes attributes);
attributes.[set some attribute]();
}
|
The available attributes are:
- method - the request method to use (GET or POST)
- multipart - whether form submittion should use content type: multipart/form-data. Implies POST method.
- event names - a list of event names for which the Ajax call will be executed. For example: click, change, keyup, etc.
- form id - the id of the form which should be submitted with this Ajax call
- submitting component name - the input name of the component which submits the form
- data type - what kind of data is expected in the response of the Ajax call
- is wicket ajax response - a flag which indicates whether the response is <ajax-response> which is handled by wicket-ajax.js or custom response type which can be handled by application's code (e.g. in IAjaxCallListener's success handler)
- preconditions - a list of preconditions which may abort the Ajax call. Return 'false' from any precondition to abort the call
- channel - the name and type of the Ajax channel to use. Channels are used to queue the Ajax requests at the client side. See org.apache.wicket.ajax.AjaxChannel javadoc for more details.
- ajax call listeners - see below for more information
- extra parameters - a map of parameters which should be added to the query string/post data of the Ajax call
- dynamic extra parameters - parameters which are calculated at the client side and added dynamically to the query string/post data of the Ajax call
- request timeout - a timeout to about the request if there is no response
- allow default - a flag which indicates whether to allow the default behavior of the HTML element which listens for the event. For example: clicking on Ajax checkbox should allow the default to actually check the box
- async - a flag that indicates whether the Ajax call should be asynchronous or not
- throttling settings - settings which define whether the Ajax call should be throttled and for how long. See org.apache.wicket.ajax.attributes.ThrottlingSettings
While constructing the JavaScript that will register the event listener for that Ajax component/behavior these settings are serialized to optimized JSON object which is passed as a parameter to Wicket.Ajax.(get|post|ajax) methods.
For example an AjaxLink contributes JavaScript similar to :
Code Block |
---|
Wicket.Ajax.get({"u":"the/url/to/the/link", "e": "click", "c":"linkId"});
|
Many of the attributes have default values which are not written in the JSON settings and they are initialized at the client side (i.e. wicket-ajax.js knows the defaults). The example above can be read as: when HTML element with id 'linkId' is clicked fire an Ajax call with Url 'the/url/to/the/link'.
Migration steps
o.a.w.ajax.IAjaxCallDecorator is replaced with o.a.w.ajax.attributes.IAjaxCallListener.
...