Author(s)Chris Turner, Eelco Hillenius, Jonathan Locke, Martijn Dashorst, Ralf Ebert
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
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;
}
};
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 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; } };