Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Add your own javascript on a Wicket Ajax component

DZone's Guide to

Add your own javascript on a Wicket Ajax component

· Java Zone
Free Resource

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

Wicket is great to turn a component into an Ajax-enabled component.
But what happens if you want to add your own javascript on that Ajax component? Because Wicket will decorate the javascript to add Ajax support, whatever you’ll put in your html will be ignored.
The solution is easy when using an IBehavior to your component.

Say you are using a WebMarkupContainer as ajax target. Everything that is Ajax-refreshed is put in it.

WebMarkupContainer wc = new WebMarkupContainer("ajax");
wc.setOutputMarkupId(true);
wc.add(new AbstractBehavior() {
@Override
public void renderHead(IHeaderResponse response) {
String js = "alert('hello');";
response.renderOnDomReadyJavascript(js);
super.renderHead(response);
}
});
wc.add(... the component that will be refreshed by Ajax...)
add(wc);

 

From http://jsoftbiz.wordpress.com/2011/06/01/add-your-own-javascript-on-a-wicket-ajax-component/

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}