This Confluence has been LDAP enabled, if you are an ASF Committer, please use your LDAP Credentials to login. Any problems file an INFRA jira ticket please.

Child pages
  • Adding Javascript from Wicket
Skip to end of metadata
Go to start of metadata

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