Wicket:通过Ajax上传数据

I've got some data in javascript on the client that I'd like to pass to my Wicket Component java code for processing (e.g. persisting).

Using an saveButton.addButtonListener(WICKET_ID_SAVEBUTTON, null, this); on a button lets the Wicket Controller (in Java) know that the button was clicket via ajax.

How can I pass some data (e.g. var mydata = ["duck", "duck", "goose"]) via additionalData or otherwise?

@Override
public void onButtonClick(String clickedButtonId, Object additionalData, AjaxRequestTarget renderTarget)

Thanks! PS: I'm using Wicket-6

You can use an AbstractDefaultAjaxBehavior and have your save button call that function.

Add the behavior to your page:

AbstractDefaultAjaxBehavior bum = new AbstractDefaultAjaxBehavior()
{
  @Override
  protected void respond(AjaxRequestTarget _target)
  {
    String data = RequestCycle.get().getRequest().getRequestParameters().getParameterValue("data").toString();
    // parse and save data
  }
};
myComponent.add(bum); // needed to allow access to getCallbackUrl()

Override renderHead in the page and setup the AjaxBehavior as a javascript function

@Override
public void renderHead(IHeaderResponse response)
{
  super.renderHead(response);
  response.render(JavaScriptHeaderItem.forScript("function myFunction(data) {Wicket.Ajax.get({'u':'"+ bum.getCallbackUrl() +"&data=' + data})}", "myFunction"));
}

Then let the save button in your markup call the myFunction(data) with the data you want to save.