wicket
Class AttributeModifier

java.lang.Object
  extended bywicket.AttributeModifier
All Implemented Interfaces:
java.io.Serializable

public class AttributeModifier
extends java.lang.Object
implements java.io.Serializable

This class allows a tag attribute of a component to be modified dynamically with a value obtained from a model object. This concept can be used to programatically alter the attributes of components, overriding the values specified in the markup. The two primary uses of this class are to allow overriding of markup attributes based on business logic and to support dynamic localization. The replacement occurs as the component tag is rendered to the response.

The attribute whose value is to be modified must be given on construction of the instance of this class along with the model containing the value to replace with. Optionally a pattern can be supplied that is a regular expression that the existing value must match before the replacement can be carried out.

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.

Instances of this class should be added to components via the Component.add(AttributeModifier)method after the component has been constucted.

It is possible to create new subclasses of AttributeModifier by overriding the newValue(String, String) method. For example, you could create an AttributeModifier subclass which appends the replacement value like this: new AttributeModifier("myAttribute", model) { protected String newValue(final String currentValue, final String replacementValue) { return currentValue + replacementValue; } };

Author:
Chris Turner, Eelco Hillenius, Jonathan Locke
See Also:
Serialized Form

Constructor Summary
AttributeModifier(java.lang.String attribute, boolean addAttributeIfNotPresent, IModel replaceModel)
          Create a new attribute modifier with the given attribute name and model to replace with.
AttributeModifier(java.lang.String attribute, IModel replaceModel)
          Create a new attribute modifier with the given attribute name and model to replace with.
AttributeModifier(java.lang.String attribute, java.lang.String pattern, boolean addAttributeIfNotPresent, IModel replaceModel)
          Create a new attribute modifier with the given attribute name and expected pattern to match plus the model to replace with.
AttributeModifier(java.lang.String attribute, java.lang.String pattern, IModel replaceModel)
          Create a new attribute modifier with the given attribute name and expected pattern to match plus the model to replace with.
 
Method Summary
 boolean isEnabled()
          Checks whether this attribute modifier is enabled or not.
protected  java.lang.String newValue(java.lang.String currentValue, java.lang.String replacementValue)
          Gets the value that should replace the current attribute value.
 void setEnabled(boolean enabled)
          Sets whether this attribute modifier is enabled or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AttributeModifier

public AttributeModifier(java.lang.String attribute,
                         boolean addAttributeIfNotPresent,
                         IModel replaceModel)
Create a new attribute modifier with the given attribute name and model to replace with. The additional boolean flag specifies whether to add the attribute if it is not present.

Parameters:
attribute - The attribute name to replace the value for
addAttributeIfNotPresent - Whether to add the attribute if it is not present
replaceModel - The model to replace the value with

AttributeModifier

public AttributeModifier(java.lang.String attribute,
                         IModel replaceModel)
Create a new attribute modifier with the given attribute name and model to replace with. The attribute will not be added if it is not present.

Parameters:
attribute - The attribute name to replace the value for
replaceModel - The model to replace the value with

AttributeModifier

public AttributeModifier(java.lang.String attribute,
                         java.lang.String pattern,
                         boolean addAttributeIfNotPresent,
                         IModel replaceModel)
Create a new attribute modifier with the given attribute name and expected pattern to match plus the model to replace with. A null pattern will match the attribute regardless of its value. The additional boolean flag specifies whether to add the attribute if it is not present.

Parameters:
attribute - The attribute name to replace the value for
pattern - The pattern of the current attribute value to match
addAttributeIfNotPresent - Whether to add the attribute if it is not present and the replacement value is not null
replaceModel - The model to replace the value with

AttributeModifier

public AttributeModifier(java.lang.String attribute,
                         java.lang.String pattern,
                         IModel replaceModel)
Create a new attribute modifier with the given attribute name and expected pattern to match plus the model to replace with. A null pattern will match the attribute regardless of its value. The attribute will not be added if it is not present.

Parameters:
attribute - The attribute name to replace the value for
pattern - The pattern of the current attribute value to match
replaceModel - The model to replace the value with
Method Detail

isEnabled

public final boolean isEnabled()
Checks whether this attribute modifier is enabled or not.

Returns:
Whether enabled or not

setEnabled

public final void setEnabled(boolean enabled)
Sets whether this attribute modifier is enabled or not.

Parameters:
enabled - Whether enabled or not

newValue

protected java.lang.String newValue(java.lang.String currentValue,
                                    java.lang.String replacementValue)
Gets the value that should replace the current attribute value.

Parameters:
currentValue - The current attribute value
replacementValue - The replacement value
Returns:
The value that should replace the current attribute value


Copyright © 2004-2005 Wicket developers. All Rights Reserved.