You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

To modify a tag attribute, there is a nifty new class called wicket.AttributeModifier.

Just add an instance of AttributeModifier to the tag's Java component.

When creating the AttributeModifier class the name of the attribue you want to modified must be passed, along with a model containing the value to use. For example:

In your HTML you would have something like this:

 <span wicket:id="alarm" class="unknown"/>Alarm Status</span>

And in your java something like this:

 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."

  • No labels