29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

In practice, it is often best to provide the JSP author with choice. By<br />

implementing the logic of the tag within a bean and providing the custom tag as a<br />

wrapper to the bean’s interface, then you may be able to provide the author with<br />

the choice of scripting or using custom tags.<br />

9.1.3 Common custom tag usages<br />

9.1.4 How they work<br />

When custom tags are used, they often perform a function that falls into one of<br />

the following categories:<br />

► Markup generation: Generation of markup language output, for example, to<br />

create an HTML form.<br />

► Scripting generation: Generation of client-side scripting code such as<br />

JavaScript, for example, to perform client-side data validation. This is<br />

illustrated in the Online Catalog sample.<br />

► Environment access: Providing access to and modification of implicit objects.<br />

► API access: Simplifying access to APIs such as JDBC, JNDI, and JavaMail.<br />

This is illustrated in the Online Catalog sample.<br />

► Content manipulation: Manipulating content before output, and caching of<br />

generated content.<br />

In order for the Web container to understand and execute a custom tag, the code<br />

implementing the tag and information on how to translate the tag and find and<br />

invoke the code must be available to the container. Tags for a particular function<br />

are normally aggregated into a tag library.<br />

Tag libraries, or taglibs, are normally packaged as JAR files. The taglib is made<br />

up of the following elements:<br />

► Tag library definition (TLD): An XML file containing elements that describe<br />

each tag in the library. The TLD will be used by the Web container during<br />

translation time to interpret each tag, and at request time to find and invoke<br />

the tag code.<br />

► Tag handler: A Java class that provides the Web container with access to the<br />

functionality of the tag. However, this does not necessarily mean that the tag<br />

handler implements the tag functionality. As we hinted, this may be contained<br />

within other classes/JavaBeans. The taglib will contain a tag handler class for<br />

each custom tag.<br />

► Supplemental classes: The implementation of a custom tag may include<br />

some optional files that, if used, need to be included within the taglib.<br />

Chapter 9. Using tag libraries 279

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!