Defining the Custom Component Tag in a Tag Library Descriptor
To define a tag, you declare it in a TLD. The web container uses the TLD to validate the tag. The set of tags that are part of the HTML render kit are defined in the
html_basicTLD.The custom tags
areaandmapare defined inbookstore.tld. Thebookstore.tldfile defines tags for all the custom components and the custom validator tag described in Creating a Custom Tag (page 406).All tag definitions must be nested inside the
taglibelement in the TLD. Each tag is defined by atagelement. Here is part of the tag definition of themaptag:<tag> <name>map</name> <tag-class>taglib.MapTag</tag-class> <attribute> <name>binding</name> <required>false</required> <deferred-value> <type> javax.faces.component.UIComponent </type> </deferred-value> </attribute> <attribute> <name>current</name> <required>false</required> <deferred-value> <type> java.lang.String </type> </deferred-value> </attribute> ... <attribute> <name>actionListener</name> <required>false</required> <deferred-method> <method-signature> void actionListener(javax.faces.event.ActionEvent) </method-signature> </deferred-method> <type>String</type> </attribute>... </tag>At a minimum, each tag must have a
name(the name of the tag) and atag-classattribute, which specifies the fully-qualified class name of the tag handler.Each attribute element defines one of the tag attributes. As described in Defining a Tag Attribute Type (page 119), the attribute element must define what kind of value the attribute accepts, which for JavaServer Faces tags is either a deferred value expression or a method expression.
To specify that an attribute accepts a deferred value expression, you define the type that the corresponding component property accepts using a
typeelement nested inside of adeferred-valueelement, as shown for thebindingandcurrentattribute definitions in the preceding code snippet.To specify that an attribute accepts a method expression, you define the signature of the method that expression references using a
method-signatureelement nested inside adeferred-methodelement, as shown by theactionListenerattribute definition in the preceding code snippet. The actual name of the method is ignored by the runtime.For more information on defining tags in a TLD, please consult the Tag Library Descriptors (page 220) section of this tutorial.