Loading...

May 13, 2009

Set applet parameter value in Wicket

A simple solution to set the value for applet parameters in Wicket is by using the WebMarkupContainer. Suppose we have the following applet element in our HTML page:

<applet code="com.mrhaki.wicket.applet.ApplicationApplet" 
    width="100%" height="100%">
    <param name="param1" wicket:id="appletParam1"/>
    <param name="param2" wicket:id="appletParam2"/>
</applet>

In the Page class we can use the following code to set the value for the parameters param1 and param2:

final SimpleAttributeModifer valueParam1 = 
    new SimpleAttributeModifier("value", "Value for param1");
final WebMarkupContainer appletParam1 = new WebMarkupContainer("appletParam1");
appletParam1.add(valueParam1);
add(appletParam1);
add(new WebMarkupContainer("appletParam2").
    add(new SimpleAttributeModifier("value", "Value for param2"));

We see a very expressive way of composing the value for the param element param1. And a very short statement to set the value for the param2 element.

The HTML after Wicket processing is now:


<applet code="com.mrhaki.wicket.applet.ApplicationApplet" 
    width="100%" height="100%">
    <param name="param1" value="Value for param1"/>
    <param name="param2" value="Value for param2"/>
</applet>

Another solution is described in the following post. A more generic Wicket component is also possible.