Taglibs are supported in JSPTemplates but are slightly different.
If you don't know how to write taglibs for normal JSPs it is a good idea to look at java.sun.com to find out how they work.
The idea is to create definitions for XML tags that html developers can use without understanding java, these xml tags can be included in JSPs and will get convered to java code when the JSP is compiled.
The example in this document is for a fictional tag to add atachemtns to mail messages. The tags could be used in a JSP page by adding the following tag to the top of the jsp page.
<%@taglib uri="/mail-taglib.tld" prefix="mail" %>and including tags such as this to reference the taglib
The taglib code has had very few changes from the J2EE spec and thus is specified in a WEB-INF/web.xml file. The WEB-INF directory should be added to the JSP directory used for JSPTemplates.
The xml file must pass validation of the J2EE dtd but the contents of the web.xml that are not related to taglibs are ignored. A copy of an existing J2EE web.xml is a good starting point but it is a good idea to cut out any non taglib related items in the JSPTemplates web.xml to avoid confustion.
The following example illustrates a minimal web.xml for JSPTemplates with nothing other that the taglib definition.
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <web-app> <taglib> <taglib-uri> mail-taglib.tld </taglib-uri> <taglib-location> mail-taglib.tld </taglib-location> </taglib> </web-app>
The mail-taglib.tld is an almost standard J2EE taglib descriptor, however the doctype tag includes a references to the dtd that is included in myjasper.jar. It is possible to include the http:// location of the web-jsptaglibrary_1_1.dtd but the JSPTemplates engine must then have an http connection at all times and will break if it does not.
A minimal example follows...
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "/org/tp23/jasper/resources/web-jsptaglibrary_1_1.dtd"> <!-- a tag library descriptor --> <taglib> <tlibversion>1.0</tlibversion> <jspversion>1.1</jspversion> <shortname>emailUtils</shortname> <uri>mail-taglib.tld</uri> <info> A tag library to set the file attachments in an email message </info> <tag> <name>attachment</name> <tagclass>com.myco.tags.AttachmentTag</tagclass> <info> Attach a file to the email session </info> <attribute> <name>filename</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>The class specified
The main difference between JSPTempltes taglibs and J2EE templates is that the pageConfig object is different.
Normally in a taglib class the following method would be implemented.
In a JSPTemplate the following method is implemented.
As you might expect the pageContext does not have references to the request or response instead use the methods in the ObjectPageContext interface.