14.3. Assigning Attributes to Tags

Allowing tags like

<prefix:name attribute1="value1" attribute2="value2" ... />

adds significant flexibility to your tag library. This section explains how to add attribute support to your tags.

The Tag Handler Class

Providing support for attributes is straightforward. Use of an attribute called attribute1 simply results in a call to a method called setAttribute1 in your class that extends TagSupport (or otherwise implements the Tag interface). The attribute value is supplied to the method as a String. Consequently, adding support for an attribute named attribute1 is merely a matter of implementing the following method:

public void setAttribute1(String value1) {
  doSomethingWith(value1);
}

Note that an attribute ...

Get Core Servlets and JavaServer Pages™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.