| Contents | Prev | Next |
|
where<tlt:twa attr1="value1">
value1 is of type AttributeClass, must contain the following declaration and methods:
private AttributeClass attr1;
setAttr1(AttributeClass ac) { ... }
AttributeClass getAttr1() { ... }
Note that if your attribute is named id, and your tag handler inherits from the TagSupport class, you do not need to define the property and set and get methods because these are already defined by TagSupport.
A tag attribute whose value is a String can name an attribute of one of the implicit objects available to tag handlers. An implicit object attribute would be accessed by passing the tag attribute value to the [set/get]Attribute method of the implicit object. This is a good way to pass scripting variable names to a tag handler where they are associated with objects stored in the page context (See "Tags That Define Scripting Variables").
attribute Element
If a tag attribute is not required, a tag handler should provide a default value.<tag> ... <attribute> <name>attr1</name> <required>true|false|yes|no</required> <rtexprvalue>true|false|yes|no</rtexprvalue> </attribute> </tag>
The attributes passed to a tag can also be validated at translation time with the isValid method of a class derived from TagExtraInfo. This class is also used to provide information about scripting variables defined by the tag (See "Tags That Define Scripting Variables").
The isValid method is passed the attribute information in a TagData object, which contains attribute-value tuples for each of the tag's attributes. Since the validation occurs at translation time, the value of an attribute that is computed at request time will be set to TagData.REQUEST_TIME_VALUE.
The tag <tlt:twa attr1="value1" /> has the following TLD attribute element:
This declaration indicates that the value of<attribute> <name>attr1</name> <required>true</required> <rtexprvalue>true</a> </attribute
attr1 can be determined at runtime.
The following isValid method checks that the value of attr1 is a valid boolean value. Note that since the value of attr1 can be computed at runtime, isValid must check whether the tag user has chosen to provide a runtime value.
public class TwaTEI extends TagExtraInfo {
public boolean isValid(Tagdata data) {
Object o = data.getAttribute("attr1");
if (o != null && o != TagData.REQUEST_TIME_VALUE) {
if (o.toLowerCase().equals("true") ||
o.toLowerCase().equals("false") )
return true;
else
return false;
}
else
return true;
}
}