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 {
		@Override
		protected void onComponentTag(ComponentTag tag) {
			super.onComponentTag(tag);
			String js = "{wicketAjaxGet('" + getCallbackUrl() + "&'+this.name+'='+wicketEncode(this.value)); return false;}";
			tag.put("onblur", js);
		}

		@Override
		protected void respond(AjaxRequestTarget target) {
			FormComponent c = getMyComponent();
			c.processInput();
			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