|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wicket.behavior.AbstractBehavior wicket.AttributeModifier
public class AttributeModifier
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
wicket.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;
}
};
Field Summary | |
---|---|
static java.lang.String |
VALUELESS_ATTRIBUTE_ADD
Marker value to have an attribute without a value added. |
static java.lang.String |
VALUELESS_ATTRIBUTE_REMOVE
Marker value to have an attribute without a value removed. |
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 | |
---|---|
void |
detachModel(Component component)
Detach the model if it was a IDetachableModel Internal method. |
protected IModel |
getReplaceModel()
Gets the replacement model. |
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 |
onComponentTag(Component component,
ComponentTag tag)
Called any time a component that has this behavior registered is rendering the component tag. |
void |
replaceAttibuteValue(Component component,
ComponentTag tag)
Checks the given component tag for an instance of the attribute to modify and if all criteria are met then replace the value of this attribute with the value of the contained model object. |
void |
setEnabled(boolean enabled)
Sets whether this attribute modifier is enabled or not. |
java.lang.String |
toString()
|
Methods inherited from class wicket.behavior.AbstractBehavior |
---|
bind, cleanup, exception, onException, onRendered, rendered |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String VALUELESS_ATTRIBUTE_ADD
public static final java.lang.String VALUELESS_ATTRIBUTE_REMOVE
Constructor Detail |
---|
public AttributeModifier(java.lang.String attribute, boolean addAttributeIfNotPresent, IModel replaceModel)
attribute
- The attribute name to replace the value foraddAttributeIfNotPresent
- Whether to add the attribute if it is not presentreplaceModel
- The model to replace the value withpublic AttributeModifier(java.lang.String attribute, IModel replaceModel)
attribute
- The attribute name to replace the value forreplaceModel
- The model to replace the value withpublic AttributeModifier(java.lang.String attribute, java.lang.String pattern, boolean addAttributeIfNotPresent, IModel replaceModel)
attribute
- The attribute name to replace the value forpattern
- The pattern of the current attribute value to matchaddAttributeIfNotPresent
- Whether to add the attribute if it is not present and the
replacement value is not nullreplaceModel
- The model to replace the value withpublic AttributeModifier(java.lang.String attribute, java.lang.String pattern, IModel replaceModel)
attribute
- The attribute name to replace the value forpattern
- The pattern of the current attribute value to matchreplaceModel
- The model to replace the value withMethod Detail |
---|
public final void detachModel(Component component)
detachModel
in interface IBehavior
detachModel
in class AbstractBehavior
component
- the model that initiates the detachementIBehavior.detachModel(Component)
public boolean isEnabled()
public final void onComponentTag(Component component, ComponentTag tag)
IBehavior
onComponentTag
in interface IBehavior
onComponentTag
in class AbstractBehavior
component
- the component that renders this tag currentlytag
- the tag that is renderedIBehavior.onComponentTag(wicket.Component,
wicket.markup.ComponentTag)
public final void replaceAttibuteValue(Component component, ComponentTag tag)
component
- The componenttag
- The tag to replace the attribute value forpublic final void setEnabled(boolean enabled)
enabled
- Whether enabled or notpublic java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
protected final IModel getReplaceModel()
protected java.lang.String newValue(java.lang.String currentValue, java.lang.String replacementValue)
currentValue
- The current attribute value. This value might be null!replacementValue
- The replacement value. This value might be null!
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |