Over a million developers have joined DZone.

Add your own javascript on a Wicket Ajax component

· Java Zone

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

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/

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

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 }}