Tag Directive
Used for declaring custom tag properties.
JSP Syntax
<%@ tag
[ display-name="name of the tag file | display-name" ]
[ body-content="scriptless|tagdependent|empty" ]
[ dynamic-attributes="page-scoped attribute" ]
[ small-icon="relativeURL" ]
[ large-icon="relativeURL" ]
[ description="text" ]
[ example="text" ]
[ language="java" ]
[ import="{package.class | package.*} , ... " ]
[ pageEncoding="{characterSet | ISO-8859-1}" ]
[ isELIgnored="true|false" ]
%>
<jsp:directive.tag tagDirectiveAttrList /> where tagDirectiveAttrList is the same as the attribute list in the JSP syntax.
XML Syntax
<jsp:directive.tag tagDirectiveAttrList />
where tagDirectiveAttrList is the same as the attribute list in the JSP syntax.
Examples
This tag accepts an arbitrary number of attributes whose values are colors and outputs a bulleted list of the attributes colored according to the values:
<colored:colored color1="red" color2="yellow" color3="blue"/>
The following code implements the preceding tag. An arbitrary number of attributes whose values are colors are stored in a Map named by the dynamic-attributes attribute of the tag directive. The JSTL forEach tag is used to iterate through the Map and the attribute keys and colored attribute values are printed in a bulleted list.
<%@ tag dynamic-attributes="colorMap"%>
<ul>
<c:forEach var="color" begin="0" items="${colorMap}">
<li>${color.key} = <font color="${color.value}">${color.value}</
font><li>
</c:forEach>
</ul>
Description
The tag directive is similar to the page directive in a JSP page, but applies to tag files instead of JSP pages. As with the page directive, a translation unit can contain more than one instance of the tag directive. All the attributes apply to the complete translation unit. However, there can be only one occurrence of any attribute or value defined by this directive in a given translation unit. With the exception of the import attribute, multiple attribute or value (re)definitions result in a translation error.
Attributes
display-name="name of the tag file |display-name"- A short name that is intended to be displayed by tools. Defaults to the name of the tag file, without the
.tagextension.
- A short name that is intended to be displayed by tools. Defaults to the name of the tag file, without the
body-content="scriptless|tagdependent|empty"- Provides information on the content of the body of this tag. Can be either
empty,tagdependent, orscriptless. A translation error results ifJSPor any other value is used. Defaults toscriptless.
- Provides information on the content of the body of this tag. Can be either
dynamic-attributes="page-scoped attribute"- Indicates whether this tag supports additional attributes with dynamic names. If present, the generated tag handler must implement the
javax.servlet.jsp.tagext.DynamicAttributesinterface, and the container must treat the tag as if its corresponding TLD entry contained<dynamic-attributes>true</dynamic-attributes>. The implementation must not reject any attribute names. The value identifies a page-scoped attribute in which to place aMapcontaining the names and values of the dynamic attributes passed during invocation of the tag. TheMapmust contain each dynamic attribute name as the key and the dynamic attribute value as the corresponding value. Only dynamic attributes with no URI are to be present in theMap; all other dynamic attributes are ignored. A translation error results if the value of thedynamic-attributesof a tag directive is equal to the value of aname-givenof a variable directive or the value of anameattribute of an attribute directive.
- Indicates whether this tag supports additional attributes with dynamic names. If present, the generated tag handler must implement the
small-icon="relativeURL"- Either a context-relative path, or a path relative to the tag source file, of an image file containing a small icon that can be used by tools. Defaults to no small icon.
- Either a context-relative path, or a path relative to the tag source file, of an image file containing a small icon that can be used by tools. Defaults to no small icon.
large-icon="relativeURL"- Either a context-relative path, or a path relative to the tag source file, of an image file containing a large icon that can be used by tools. Defaults to no large icon.
- Either a context-relative path, or a path relative to the tag source file, of an image file containing a large icon that can be used by tools. Defaults to no large icon.
description="text"example="text"- Defines an arbitrary string that presents an informal description of an example of a use of this action. Defaults to no example.
- Defines an arbitrary string that presents an informal description of an example of a use of this action. Defaults to no example.
language="java"import="{package.class|package.*} , ... "pageEncoding="{characterSet| ISO-8859-1}"- Carries the same syntax and semantics of the
pageEncodingattribute in thepagedirective. However, there is no corresponding global configuration element in web.xml. ThepageEncodingattribute cannot be used in tag files in XML syntax.
- Carries the same syntax and semantics of the
isELIgnored="true|false"
