THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
How to modify an attribute on a HTML tag
To modify a tag attribute, there is a nifty new class called wicket.AttributeModifier.
...
In your HTML you would have something like this:
Code Block | ||||
---|---|---|---|---|
| ||||
| ||||
<span wicket:id="alarm" class="unkown"/>Alarm Status</span> |
And in your java something like this:
Panel |
---|
Code Block |
Label alarmLabel = new Label("alarm", new PropertyModel(test, "alarmState"));
alarmLabel.add(new AttributeModifier("class", new Model() {
public Object getObject(final Component component) {
String cssClass;
if ( test.getAlarmState() )
cssClass = "alarm";
} else {
cssClass="noAlarm";
}
return cssClass;
}
}));
add(alarmLabel);
|
If the attribute is not already present it will not, by default, be created. To quote the Javadoc: "If an attribute is not in the markup, this modifier will add an attribute to
the tag only if addAttributeIfNotPresent is true and the replacement value is
not null."