Java Reference
In-Depth Information
The JSP using our tag file would need to send the fragment via the <jsp:fragment>
<jsp:attribute name="myattribute">
<!-- Any HTML or JSP markup can be put here -->
</jsp:attribute> </
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
<%@ 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"/>
The following JSP illustrates how to use our custom tag.
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<%@ taglib prefix="ct" tagdir="/WEB-INF/tags/" %>
<%@ page import="com.ensode.netbeansbook.AddressBean" %> <!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
""> <%
AddressBean addressBean = new AddressBean();
addressBean.setLine1("123 Tennis Ct");
Search WWH ::

Custom Search