This article will give some general pointers on howto do javascript integration, it’ll give some tip on how to make it easier to for you. And also a recommended way on project structuring.
Howto do it:
Javascript bridge
If you need a javascript bridge between the javascript library and wicket a very nice way are todo it like this:
https://wicket-stuff.svn.sourceforge.net/svnroot/wicket-stuff/trunk/wicket-contrib-openlayers/src/main/java/org/wicketstuff/openlayers/wicket-openlayersmap.js
Use the wicket namespace for a cleaner approach(like above), and remember to place your data in an array, so you can have multiple of the same components on the same page. Like so:
var Wicket;
if (!Wicket) {
Wicket = {};
} else {
if (typeof Wicket != "object") {
throw new Error("Wicket already exists and is not an object");
}
}
Wicket.omaps = {};
function WicketOMap(id, options) {
Wicket.omaps[id] = this;
}
Lots of dynamic stuff?
If you have lots of dynamic stuff you can use a texttemplate to interpolate your variables with it works really smooth, heres an example:
...
HashMap variables = new HashMap();
variables.put("alert", "helloworld");
TextTemplate textTemplate=new TextTemplate();
textTemplate.interpolate(variables);
String js= textTemplate.asString();
…
corrosponding java script, notice the template signature ${…}
alert("${alert}");
So above code will produce a javascript string ‘alert(“hello world”)’ very useful.
Using a behaviour
Behaviours are nice if you need some special that modifies the component you want to add too. It’s an easy way of getting information like markupid etc. Its good because you can access the component that you bind to, so you may put in javascript, add attributemodifiers etc for it.
Virtual tour of Mootips
Heres a virtual tour of Mootips javascript integration
go here for the minis wiki