Add your own javascript on a Wicket Ajax component
Join the DZone community and get the full member experience.
Join For FreeWicket 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/
Opinions expressed by DZone contributors are their own.
Comments