org.apache.wicket.behavior
Class AttributeAppender

java.lang.Object
  extended by org.apache.wicket.behavior.Behavior
      extended by org.apache.wicket.AttributeModifier
          extended by org.apache.wicket.behavior.AttributeAppender
All Implemented Interfaces:
java.io.Serializable, IClusterable, IComponentAwareEventSink, IComponentAwareHeaderContributor

public class AttributeAppender
extends AttributeModifier

AttributeModifier that appends the given value, rather than replace it. This is especially useful for adding CSS classes to markup elements, or adding JavaScript snippets to existing element handlers.

     <a href="#" wicket:id="foo" class="link" onmouseover="doSomething()">
 
can be modified with these AttributeAppenders:
 link.add(new AttributeAppender("class", Model.of("hot")));
 link.add(new AttributeAppender("onmouseover", Model.of("foo();return false;")).setSeparator(";"));
 
this will result in the following markup:
     <a href="#" wicket:id="foo" class="link hot" onmouseover="doSomething();foo();return false;">
 

Author:
Martijn Dashorst
See Also:
AttributeModifier.append(String, IModel), AttributeModifier.append(String, Serializable), AttributeModifier.prepend(String, IModel), AttributeModifier.prepend(String, Serializable), Serialized Form

Field Summary
 
Fields inherited from class org.apache.wicket.AttributeModifier
VALUELESS_ATTRIBUTE_ADD, VALUELESS_ATTRIBUTE_REMOVE
 
Constructor Summary
AttributeAppender(java.lang.String attribute, boolean addAttributeIfNotPresent, IModel<?> appendModel, java.lang.String separator)
          Deprecated. use AttributeAppender(String, IModel) instead.
AttributeAppender(java.lang.String attribute, IModel<?> replaceModel)
          Creates an attribute modifier that concatenates the replaceModel to the attribute's current value, optionally separated by the separator.
AttributeAppender(java.lang.String attribute, IModel<?> appendModel, java.lang.String separator)
          Creates an AttributeModifier that appends the appendModel's value to the current value of the attribute, and will add the attribute when it is not there already.
AttributeAppender(java.lang.String attribute, java.io.Serializable value)
          Creates an attribute modifier that appends the value to the attribute's current value, optionally separated by the separator.
 
Method Summary
 java.lang.String getSeparator()
          Gets the separator used by attribute appenders and prependers.
protected  java.lang.String newValue(java.lang.String currentValue, java.lang.String appendValue)
          Gets the value that should replace the current attribute value.
 AttributeAppender setSeparator(java.lang.String separator)
          Sets the separator used by attribute appenders and prependers.
 java.lang.String toString()
           
 
Methods inherited from class org.apache.wicket.AttributeModifier
append, append, detach, getAttribute, getReplaceModel, onComponentTag, prepend, prepend, remove, replace, replace, replaceAttributeValue
 
Methods inherited from class org.apache.wicket.behavior.Behavior
afterRender, beforeRender, bind, canCallListenerInterface, getStatelessHint, isEnabled, isTemporary, onConfigure, onEvent, onException, renderHead, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AttributeAppender

@Deprecated
public AttributeAppender(java.lang.String attribute,
                                    boolean addAttributeIfNotPresent,
                                    IModel<?> appendModel,
                                    java.lang.String separator)
Deprecated. use AttributeAppender(String, IModel) instead.

Creates an AttributeModifier that appends the appendModel's value to the current value of the attribute, and will add the attribute when addAttributeIfNotPresent is true.

Parameters:
attribute - the attribute to append the appendModels value to
addAttributeIfNotPresent - when true, adds the attribute to the tag
appendModel - the model supplying the value to append
separator - the separator string, comes between the original value and the append value

AttributeAppender

public AttributeAppender(java.lang.String attribute,
                         IModel<?> replaceModel)
Creates an attribute modifier that concatenates the replaceModel to the attribute's current value, optionally separated by the separator.

Parameters:
attribute -
replaceModel -

AttributeAppender

public AttributeAppender(java.lang.String attribute,
                         java.io.Serializable value)
Creates an attribute modifier that appends the value to the attribute's current value, optionally separated by the separator.

Parameters:
attribute -
value -

AttributeAppender

public AttributeAppender(java.lang.String attribute,
                         IModel<?> appendModel,
                         java.lang.String separator)
Creates an AttributeModifier that appends the appendModel's value to the current value of the attribute, and will add the attribute when it is not there already.

Parameters:
attribute - the attribute to append the appendModels value to
appendModel - the model supplying the value to append
separator - the separator string, comes between the original value and the append value
Method Detail

getSeparator

public java.lang.String getSeparator()
Gets the separator used by attribute appenders and prependers.

Returns:
the separator used by attribute appenders and prependers.

setSeparator

public AttributeAppender setSeparator(java.lang.String separator)
Sets the separator used by attribute appenders and prependers.

Parameters:
separator - a space, semicolon or other character used to separate the current value and the appended/prepended value.
Returns:
this

newValue

protected java.lang.String newValue(java.lang.String currentValue,
                                    java.lang.String appendValue)
Description copied from class: AttributeModifier
Gets the value that should replace the current attribute value. This gives users the ultimate means to customize what will be used as the attribute value. For instance, you might decide to append the replacement value to the current instead of just replacing it as is Wicket's default.

Overrides:
newValue in class AttributeModifier
Parameters:
currentValue - The current attribute value. This value might be null!
appendValue - The replacement value. This value might be null!
Returns:
The value that should replace the current attribute value

toString

public java.lang.String toString()
Overrides:
toString in class AttributeModifier
See Also:
Object.toString()


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.