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.
Usage of new API
AjaxRequestAttributes interface defines possible configuration options for AjaxRequest. AjaxRequestAttributesImpl is a simple (possibly delegating) implementation.
Example of creating Ajax link that displays an confirmation window:
add(new AjaxLink("link")
{
public AjaxRequestAttributes getAttributes()
{
return new AjaxRequestAttributesImpl(super.getAttributes())
{
public FunctionList getPreconditions()
{
return super.getPreconditions()
.add("function(requestQueueItem) { return confirm('Really?'); }");
}
}
}
public void onClick(AjaxRequestTarget target)
{
...
}
}
TODO: Asynchronous preconditions would be nice and required for things like custom confirmation windows.
Example of Ajax link with custom URL parameters.
add(new AjaxLink("link")
{
public AjaxRequestAttributes getAttributes()
{
return new AjaxRequestAttributesImpl(super.getAttributes())
{
public Map<String, Object> getUrlArguments()
{
Map<String, Object> args = super.getUrlArguments();
args.put("param1", "value1");
return args;
}
}
}
public void onClick(AjaxRequestTarget target)
{
...
}
}
Example of Ajax link with URL parameters added dynamically from _javascript_.
add(new AjaxLink("link")
{
public AjaxRequestAttributes getAttributes()
{
return new AjaxRequestAttributesImpl(super.getAttributes())
{
public FunctionList getUrlArgumentMethods()
{
return super.getUrlArgumentMethods()
.add("function(requestQueueItem) { return { x:4, y:someJavascriptExpression() }; }");
}
}
}
public void onClick(AjaxRequestTarget target)
{
...
}
}