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

The single app analytics solutions to take your web and mobile apps to the next level.  Try today!  Brought to you in partnership with CA Technologies

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/

CA App Experience Analytics, a whole new level of visibility. Learn more. Brought to you in partnership with CA Technologies.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

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

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}