org.apache.wicket
public class AttributeModifier extends Behavior implements IClusterable
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.
If an attribute is not in the markup, this modifier will add an attribute.
Instances of this class should be added to components via the Component.add(Behavior...)
method after the component has been constructed.
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; } };
Modifier and Type | Class and Description |
---|---|
static class |
AttributeModifier.ValuelessAttributeAddModel
A dynamic model that returns the marker value
VALUELESS_ATTRIBUTE_ADD
to prevent making copies of it via (de)serialization |
static class |
AttributeModifier.ValuelessAttributeRemoveModel
A dynamic model that returns the marker value
VALUELESS_ATTRIBUTE_REMOVE
to prevent making copies of it via (de)serialization |
Modifier and Type | Field and Description |
---|---|
static String |
VALUELESS_ATTRIBUTE_ADD
Marker value to have an attribute without a value added.
|
static String |
VALUELESS_ATTRIBUTE_REMOVE
Marker value to have an attribute without a value removed.
|
Constructor and Description |
---|
AttributeModifier(String attribute,
boolean addAttributeIfNotPresent,
IModel<?> replaceModel)
Deprecated.
AttributeModifier will now always add the attribute if not present, use
AttributeModifier(String, IModel) instead |
AttributeModifier(String attribute,
IModel<?> replaceModel)
Create a new attribute modifier with the given attribute name and model to replace with.
|
AttributeModifier(String attribute,
Serializable value)
Create a new attribute modifier with the given attribute name and model to replace with.
|
Modifier and Type | Method and Description |
---|---|
static AttributeAppender |
append(String attributeName,
IModel<?> value)
Creates a attribute modifier that appends the current value with the given
value
using a default space character (' ') separator. |
static AttributeAppender |
append(String attributeName,
Serializable value)
Creates a attribute modifier that appends the current value with the given
value
using a default space character (' ') separator. |
void |
detach(Component component)
Detach the value if it was a
IDetachable . |
String |
getAttribute() |
protected IModel<?> |
getReplaceModel()
Gets the replacement model.
|
protected String |
newValue(String currentValue,
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.
|
static AttributeAppender |
prepend(String attributeName,
IModel<?> value)
Creates a attribute modifier that prepends the current value with the given
value
using a default space character (' ') separator. |
static AttributeAppender |
prepend(String attributeName,
Serializable value)
Creates a attribute modifier that prepends the current value with the given
value
using a default space character (' ') separator. |
static AttributeModifier |
remove(String attributeName)
Creates a attribute modifier that removes an attribute with the specified name
|
static AttributeModifier |
replace(String attributeName,
IModel<?> value)
Creates a attribute modifier that replaces the current value with the given value.
|
static AttributeModifier |
replace(String attributeName,
Serializable value)
Creates a attribute modifier that replaces the current value with the given value.
|
void |
replaceAttributeValue(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.
|
String |
toString() |
afterRender, beforeRender, bind, canCallListenerInterface, getStatelessHint, isEnabled, isTemporary, onConfigure, onEvent, onException, onRemove, renderHead, unbind
public static final String VALUELESS_ATTRIBUTE_ADD
public static final String VALUELESS_ATTRIBUTE_REMOVE
@Deprecated public AttributeModifier(String attribute, boolean addAttributeIfNotPresent, IModel<?> replaceModel)
AttributeModifier(String, IModel)
insteadattribute
- 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(String attribute, IModel<?> replaceModel)
attribute
- The attribute name to replace the value forreplaceModel
- The model to replace the value withpublic AttributeModifier(String attribute, Serializable value)
attribute
- The attribute name to replace the value forvalue
- The value for the attributepublic final void detach(Component component)
IDetachable
. Internal method, shouldn't be called from
the outside. If the attribute modifier is shared, the detach method will be called multiple
times.public final String getAttribute()
public final void onComponentTag(Component component, ComponentTag tag)
Behavior
onComponentTag
in class Behavior
component
- the component that renders this tag currentlytag
- the tag that is renderedpublic final void replaceAttributeValue(Component component, ComponentTag tag)
component
- The componenttag
- The tag to replace the attribute value forprotected final IModel<?> getReplaceModel()
protected String newValue(String currentValue, String replacementValue)
currentValue
- The current attribute value. This value might be null!replacementValue
- The replacement value. This value might be null!public static AttributeModifier replace(String attributeName, IModel<?> value)
attributeName
- value
- public static AttributeModifier replace(String attributeName, Serializable value)
attributeName
- value
- public static AttributeAppender append(String attributeName, IModel<?> value)
value
using a default space character (' ') separator.attributeName
- value
- AttributeAppender
public static AttributeAppender append(String attributeName, Serializable value)
value
using a default space character (' ') separator.attributeName
- value
- AttributeAppender
public static AttributeAppender prepend(String attributeName, IModel<?> value)
value
using a default space character (' ') separator.attributeName
- value
- AttributeAppender
public static AttributeAppender prepend(String attributeName, Serializable value)
value
using a default space character (' ') separator.attributeName
- value
- AttributeAppender
public static AttributeModifier remove(String attributeName)
attributeName
- the name of the attribute to be removedCopyright © 2006–2018 Apache Software Foundation. All rights reserved.