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

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

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/

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}