Java Reference
In-Depth Information
L ISTING 19.6
Continued
// used by the parent tag.
// This is just good practice for when you start creating
// hierarchies of tags.
super.release();
// Reset the name to an empty String
name = new String();
}
}
There are only a couple of new things to notice here. The first is the name attribute and the
setName() method. This is the attribute/method matching that is used to set attribute values as
we discussed earlier. The class level attribute name is prepended with set and the first letter of
the attribute is capitalized to perform this matching.
To deploy this new tag you need to add an entry to the tld , compile the HelloAttributeTag ,
and move the class file to the <SERVER_ROOT>/webapps/djs/WEB-INF/classes/com/djs/
directory. The code snippet that needs to be added to the tld follows:
<tag>
<name>helloAttribute</name>
<tagclass>com.djs.HelloAttributeTag</tagclass>
<bodycontent>JSP</bodycontent>
<info>Just Says Hello to the Body</info>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
The only real change to this tag element is the addition of the attribute element. In this ele-
ment you state three things. You first name the attribute, which is name for this tag. You then
state whether the attribute is required. This can be either true or false . The final addition to
the attribute element is the rtexprvalue element. This states whether the value of the
attribute can be an evaluated expression. The options are true or false .
To see this tag in action, use the JSP found in Listing 19.7.
L ISTING 19.7
HelloAttribute.jsp
<%@ taglib uri=”/djs” prefix=”djs” %>
<html>
<body>
Search WWH ::




Custom Search