Installation Docs
API Docs


Implementing Taglibs

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
<mail:image filename="NEWcurrentgraph.gif"/>

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"

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"
      <!-- a tag library descriptor -->
        A tag library to set the file attachments in an email message
          <info> Attach a file to the email session </info>
The class specified com.myco.tags.AttachmentTag should be similar to theJ2EE specification and subclass javax.servlet.jsp.tagext.TagSupport.

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.
public void setPageContext(PageContext pageContext)
In a JSPTemplate the following method is implemented.
public void setPageContext(org.tp23.jspObjectPageContext pageContext)

As you might expect the pageContext does not have references to the request or response instead use the methods in the ObjectPageContext interface.