Java Reference
In-Depth Information
The JSP using our tag file would need to send it the fragment via the
<jsp:fragment> action.
<prefix:tagname>
<jsp:attribute name="myattribute">
<!-- Any HTML or JSP markup can be put here -->
</jsp:attribute>
</prefix:tagname>
The rest of our example generates an HTML table with input fields and tables (for
simplicity and brevity, only US addresses are supported, and only a small subset of
US states are used as drop-down options).
A JSP invoking our tag would need to include our tag library via the
taglib directive:
<%@ taglib prefix="ct" tagdir="/WEB-INF/tags/" %>
Our custom tag library would consist of all custom tags placed in the WEB-INF/tags
directory in our web application. For our custom tags, we used the tagdir attribute
of the taglib directive to indicate the location of our tags.
All of our tags must be either directly under WEB-INF/tags or in a
subdirectory of WEB-INF/tags . A custom tag library consists of all
custom tags under a single directory.
Our tag can then be invoked by placing the following markup in the JSP file:
<ct:address addressType="home"/>
Custom JSP tags can contain a body. The JSP invoking our tag would look like the
following example:
<prefix:sometag>
<b>Hello there!</b>
</prefix:sometag>
If our tag contains <jsp:attribute> actions, we need to place its body
between <jsp:body> and </jsp:body> tags.
Any HTML or JSP markup can be placed in the body of our tag. Our tag renders its
body by placing a <jsp:doBody> action in the location where we wish to render
its body.
 
Search WWH ::




Custom Search