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.

These are:<br />

– TagExtraInfo: Provides additional information, over and above that<br />

contained within the TLD, about a custom tag.<br />

– BeanInfo class: Tag handlers are themselves JavaBeans, and the Web<br />

container will inspect them to obtain properties and methods. This can be<br />

aided by a BeanInfo class for each tag handler.<br />

The programmer downloads these files and puts them where they will be<br />

available to the application. A directive is added to the JSP that refers to the<br />

library and assigns it a prefix. In the JSP code, the prefix is used to invoke tags<br />

within the library. The Web application deployment descriptor (web.xml) provides<br />

the link between the directive used in the application and the actual JAR file<br />

containing the classes that execute the function.<br />

9.1.5 An inside look at a taglib<br />

Let us take a look at a simple tag that displays a hello message. The elements of<br />

a taglib include:<br />

► An implementation bean<br />

► A tag handler class<br />

► A tag library descriptor<br />

It is important to note that if you are simply using an existing taglib, the only thing<br />

you really need to know is that these things exist. We want to show you a quick<br />

example to take the mystery out of taglibs.<br />

Implementation bean<br />

The actual tag implementation is contained within a JavaBean called HelloBean,<br />

shown in Example 9-1. The bean supplies one method, hello(), which accepts a<br />

String argument. The method outputs a message.<br />

Example 9-1 Simple custom tag example: HelloBean.java<br />

//Simple custom tag example: HelloBean.java<br />

package com.ibm.itso.j2eebook.tagexamples.beans;<br />

/**<br />

* JavaBean which displays a Hello message.<br />

*<br />

* @author: Adrian Spender<br />

*/<br />

public class HelloBean {<br />

/**<br />

* HelloBean default constructor.<br />

280 <strong>IBM</strong> <strong>WebSphere</strong> <strong>Application</strong> <strong>Server</strong> - Express V5.0.2 Developer Handbook

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

Saved successfully!

Ooh no, something went wrong!