JSP Custom Tags: Bringing Components to the Web - Creating a Custom Tag continued (Page 3 of 4 )
Creating the TLD File
As mentioned before, a TLD file is an XML document that describes the library. The TLD contains the information about the library as a whole, as well as about individual tags. The information about the complete library is provided with the XML tags in the following table.
XML Tag
Definition
<taglib>
The tag library itself. The following tags are the child nodes of this tag.
<tlibversion>
The tag library's version.
<jspversion>
The JSP version that is required to make the tag work.
<shortname>
A simple default name with a mnemonic value. For example, <shortname> may be used as the preferred prefix value in taglib directives and/or to create prefixes for IDs.
<uri>
An optional URI that uniquely identifies the tag library.
<info>
Descriptive information about the tag library.
The tag specific info is described using the following XML tags:
<tag>: The data about the tag itself is described by the siblings of this tag, which are detailed below.
<name>: The name by which the tag would be accessed is given by this XML element.
<tagclass>: The name of the class that handles the tag, a.k.a the tag handler's name. the value of this element must be fully qualified Java name.
<bodycontent>: The value of this tag determines whether the content of the tag has to be considered or not. There can be three values: empty to indicate that the tag has no body, and that an error will be produced if it has one; tagdependent, to indicate that the body is only processed by tag; and JSP, which states that the JSP container should evaluate any body of the tag.
<attribute>: The info about the tag's attribute. The following child nodes provides various information:
<name>: Name of the attribute.
<required>: Declares whether the attribute is mandatory or not.
<rtexpvalue>: Lets the <attribute> tag use a runtime expression value if the value of this element is set to "true" or "yes."
That covers the contents of the TLD file. In the next section I will be creating a tag. In it the above tags will be used to create the mapping. So here comes the (nearly) real world example.