Skip to content

How to use existing addons

Asterios edited this page Sep 16, 2016 · 16 revisions

This is description how to use an addon. For our example we will take the wicket-tooltipster addon.

If you want to use the wicket-tooltipster addon in your wicket aplication you have to add the dependency in your 'pom.xml' file.

<dependency>
   <groupId>de.alpharogroup</groupId>
   <artifactId>wicket-tooltipster</artifactId>
</dependency>

Now you can use the wicket-tooltipster addon to generate javascript for the library tooltipster.js and add it to a behavior class. The awesome tooltipster.js library creates tooltips for components so if you want to add a tooltip for a Label you have to create this Label instance and an instance of the TooltipsterSettings:

Label label = new Label("tooltip", Model.of("A tooltip."));
label.setOutputMarkupId(true);
add(label);
TooltipsterSettings tooltipsterSettings = TooltipsterSettings.builder().build();

Consider to call the label.setOutputMarkupId(true) method to the label for generate the 'id'-attribute. Then you set the attributes you need for the js lib tooltipster.js:

tooltipsterSettings.getAnimation().setValue("grow");
tooltipsterSettings.getArrow().setValue(false);
tooltipsterSettings.getContent().setValue("Loading foo...");

For a detailed description of all attributes of tooltipster.js consider to visit the tooltipster.js website If all attributes are set you have to give the tooltipsterSettings instance and the markup id from the label to a JsGenerator in this case the TooltipsterJsGenerator:

TooltipsterJsGenerator tooltipsterJsGenerator = new TooltipsterJsGenerator(
			tooltipsterSettings, label.getMarkupId());
String js = tooltipsterJsGenerator.generateJs();

This generates the needed javascript code that you have to add to the label over a Behavior. I have implemented an Behavior(JavascriptAppenderBehavior) that does this:

label.add(JavascriptAppenderBehavior.builder().id("tooltip_" + label.getMarkupId())
			.javascript(js).build());

At the end you add the label to the parent component.

The class JavascriptAppenderBehavior is in the lib jaulp.wicket.behaviors project. It is a Behavior that adds javascript to a component over a Behavior. You can create of course your own Behavior that does this.

Clone this wiki locally