| Apache Wicket > Index > Wicket 1.5 Ajax |
I'm in process of rewriting the Ajax support for 1.5. The current (very experimental) code is available at http://svn.apache.org/repos/asf/wicket/sandbox/knopp/experimental in package org.apache.wicket.ajaxng (will be later renamed to ajax replacing current ajax classes).
Some of the improvements over current Ajax implementation.
onclick="var wcall=wicketAjaxGet('../?wicket:interface=:2:c1::IBehaviorListener:1:1',null,null, function() {return Wicket.$('c12') != null;}.bind(this));
while for the same effect new Ajax implementation only generates
W.e('click',{c:"c12",b:0});
AjaxRequestAttributes defines possible configuration options for AjaxRequest.
Example of creating Ajax link that displays an confirmation window:
add(new AjaxLink("link") { protected void updateAttributes(AjaxRequestAttributes attributes) { super.updateAttributes(attributes); attributes.getPreconditions() .add("function(requestQueueItem) { return confirm('Really?'); }"); } public void onClick(AjaxRequestTarget target) { ... } }
Note: Asynchronous preconditions are also supported, see AjaxRequestAttributes#getPreconditions.
Example of Ajax link with custom URL parameters.
add(new AjaxLink("link") { protected void updateAttributes(AjaxRequestAttributes attributes) { super.updateAttributes(attributes); attributes.getUrlArguments().put("param1", "value1"); } public void onClick(AjaxRequestTarget target) { ... } }
Example of Ajax link with URL parameters added dynamically from javascript.
add(new AjaxLink("link") { protected void updateAttributes(AjaxRequestAttributes attributes) { super.updateAttributes(attributes); attributes.getUrlArgumentMethods() .add("function(requestQueueItem) { return { x:4, y:someJavascriptExpression() }; }"); } public void onClick(AjaxRequestTarget target) { ... } }