Basically, you should use the updateAjaxAttributes()
and renderHead()
in a custom AbstractAjaxBehaviour
See for more detail here:
http://wickedsource.org/2013/01/07/rolling-your-own-ajax-behavior-with-wicket/
Retrieved from google cache, relevant code (written by Tom Hombergs):
public class MyAjaxBehavior extends AbstractDefaultAjaxBehavior {
@Override
protected void respond(AjaxRequestTarget target) {
RequestCycle cycle = RequestCycle.get();
WebRequest webRequest = (WebRequest) cycle.getRequest();
StringValue param1 = webRequest.getQueryParameters().getParameterValue("param1");
StringValue param2 = webRequest.getQueryParameters().getParameterValue("param2");
// do whatever you need with param1 and param2
}
@Override
public CharSequence getCallbackScript() {
String script = super.getCallbackScript().toString();
script = script.replace("\"PLACEHOLDER1\"", "param1Value");
script = script.replace("\"PLACEHOLDER2\"", "param2Value");
return script;
}
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
attributes.getExtraParameters().put("param1", "PLACEHOLDER1");
attributes.getExtraParameters().put("param2", "PLACEHOLDER2");
}
@Override
public void renderHead(Component component, IHeaderResponse response) {
super.renderHead(component, response);
String script = "var param1Value = My.JavaScript.Module.calculate1();";
script += "var param2Value = My.JavaScript.Module.calculate2();";
script += getCallbackScript();
response.render(OnDomReadyHeaderItem.forScript(script));
}
}