background image

PackagedTag Files

<< Declaring Tag Files | Declaring Tag Handlers >>
<< Declaring Tag Files | Declaring Tag Handlers >>

PackagedTag Files

The web container generates an implicit tag library for each directory under and including
/WEB-INF/tags/
. There are no special relationships between subdirectories; they are allowed
simply for organizational purposes. For example, the following web application contains three
tag libraries:
/WEB-INF/tags/
/WEB-INF/tags/a.tag
/WEB-INF/tags/b.tag
/WEB-INF/tags/foo/
/WEB-INF/tags/foo/c.tag
/WEB-INF/tags/bar/baz/
/WEB-INF/tags/bar/baz/d.tag
The implicit TLD for each library has the following values:
tlib-version
for the tag library. Defaults to 1.0.
short-name
is derived from the directory name. If the directory is /WEB-INF/tags/, the
short name is simply tags. Otherwise, the full directory path (relative to the web
application) is taken, minus the /WEB-INF/tags/ prefix. Then all / characters are replaced
with - (hyphen), which yields the short name. Note that short names are not guaranteed to
be unique.
A tag-file element is considered to exist for each tag file, with the following subelements:
The name for each is the filename of the tag file, without the .tag extension.
The path for each is the path of the tag file, relative to the root of the web application.
So, for the example, the implicit TLD for the /WEB-INF/tags/bar/baz/ directory would be as
follows:
<taglib>
<tlib-version>1.0</tlib-version>
<short-name>bar-baz</short-name>
<tag-file>
<name>d</name>
<path>/WEB-INF/tags/bar/baz/d.tag</path>
</tag-file>
</taglib>
Despite the existence of an implicit tag library, a TLD in the web application can still create
additional tags from the same tag files. To accomplish this, you add a tag-file element with a
path
that points to the tag file.
Packaged Tag Files
Tag files can be packaged in the /META-INF/tags/ directory in a JAR file installed in the
/WEB-INF/lib/
directory of the web application. Tags placed here are typically part of a
reusable library of tags that can be used easily in any web application.
Tag Library Descriptors
The Java EE 5 Tutorial · September 2007
250