Add Javascript in serverside code using AjaxRequestTarget#appendJavascript or #prependJavascript.
And there's still the option to use an IAjaxCallDecorator (example).

TODO: examples!

Adding a Wicket JS call to a component can be accomplished by adding the following Ajax behavior to a component (this example would only apply to a component that has an onblur event associated with it):


	protected class MyBehavior extends AbstractDefaultAjaxBehavior {
		protected void onComponentTag(ComponentTag tag) {
			String js = "{wicketAjaxGet('" + getCallbackUrl() + "&''='+wicketEncode(this.value)); return false;}";
			tag.put("onblur", js);

		protected void respond(AjaxRequestTarget target) {
			FormComponent c = getMyComponent();
			if (c.hasErrorMessage()) {
				Serializable msg = c.getFeedbackMessage().getMessage();
				// do something with the message


Adding ajax to events:

body.add(new AjaxEventBehavior("onload"){
	protected void onEvent(AjaxRequestTarget target){
		// do something
  • No labels