TagData Class  
 
Class name:

javax.servlet.jsp.tagext.TagData

 
Extends:

None

 
Implements:

Cloneable

 
Implemented by:

Internal container-dependent class. Most containers use the reference implementation of the class (developed in the Apache Jakarta project).

 
Description

TagData instances are created by the web container during the translation phase. They provide information about the attribute values specified for a custom action to the TagExtraInfo subclass for the corresponding tag handler, if any.

 
Example

After the web container has checked everything it can on its own based on attribute information in the TLD, it looks for a TagExtraInfo subclass, defined by the <teiclass> element, for the custom action. If one is defined, it puts all the attribute information in an instance of the TagData class and calls the TagExtraInfo isValid() method:

public boolean isValid(TagData data) {
    // Mutually exclusive attributes
    if (data.getAttribute("attr1") != null &
        data.getAttribute("attr2" != null) {
        return false;
    }

    // Dependent optional attributes
    if (data.getAttribute("attr3") != null &
        data.getAttribute("attr4" == null) {
        return false;
    }
    return true;
}

A TagExtraInfo subclass can use the TagData instance to verify that all attribute dependencies are okay, as in this example. Unfortunately, in JSP 1.1 there's no way to generate an appropriate error message; the method can only return false to indicate that something is not quite right. This will hopefully be rectified in a future version of JSP.

TagData()  
public TagData(Object[][] atts)

Creates a new instance with the attribute name/value pairs specified by the Object[][]. Element 0 of each Object[] contains the name; element 1 contains the value or REQUEST_TIME_VALUE (if the attribute value is defined as a request-time value, or JSP expression).

TagData()  
public TagData(java.util.Hashtable attrs)

Creates a new instance with the attribute name/value pairs specified by the Hashtable.

getAttribute()  
public Object getAttribute(String attName)

Returns the specified attribute value as a String or as the REQUEST_TIME_VALUE object (if the attribute value is defined as a request-time value, or JSP expression).

getAttributeString()  
public String getAttributeString(String attName)

Returns the specified attribute value as a String. A ClassCastException is thrown if the attribute value is defined as a request-time value (a JSP expression).

getId()  
public String getId()

Returns the attribute named id as a String, or null if it is not found.

setAttribute()  
public void setAttribute(String attName, Object value)

Sets the specified attribute to the specified value.