EchoAttributesTag.java
public class EchoAttributesTag
extends SimpleTagSupport
implements DynamicAttributes
{
private ArrayList<String> keys = new ArrayList<String>();
private ArrayList<Object> values = new ArrayList<Object>();
@Override
public void doTag() throws JspException, IOException {
JspWriter out = getJspContext().getOut();
for( int i = 0; i < keys.size(); i++ ) {
String key = keys.get( i );
Object value = values.get( i );
out.println( "<li>" + key + " = " + value + "</li>" );
}
}
@Override
public void setDynamicAttribute( String uri, String localName,
Object value )
throws JspException
{
keys.add( localName );
values.add( value );
}
}
<my:echoAttributes x="1" y="2" z="3" r="red" g="green" b="blue"/>
Invocation 1 (six attributes)
- x = 1
- y = 2
- z = 3
- r = red
- g = green
- b = blue