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.

There is one tag element for each custom tag within the library. The bodycontent<br />

element is, according to the JSP specification, primarily for use by authoring<br />

tools. It may take one of three values: tag dependent, JSP, or empty. In practice, it<br />

is most often used to define tags that will have no body content by specifying<br />

empty.<br />

The tag element will include an attribute element for each attribute of the tag. The<br />

attribute element has three subelements:<br />

► Name: A required element and defines the name of the attribute<br />

► Required element: If true, tells the Web container that a translation-time error<br />

should occur if the attribute is not specified within a given tag instance<br />

► rtexprvalue: If true, specifies that the Web container should allow the attribute<br />

value to be expressed using a JSP expression tag<br />

9.1.6 Using tag libraries<br />

Now that you have seen what a taglib is, you can see how simple it is to use it<br />

within an application. The key to using a tag library is to make the TLD available<br />

to the Web container. This usually involves three steps:<br />

► Identifying the location of the TLD using a taglib directive in the JSP where<br />

the taglib is to be used. The taglib directive can point directly to the TLD, or it<br />

can use a URI that maps to a deployment descriptor entry.<br />

► An entry in the Web application deployment descriptor that identifies the TLD<br />

location and URI.<br />

► Invoking the taglib in the code.<br />

Taglib directive<br />

The taglib directive tells the Web container how to find the TLD for the taglib and<br />

the identifier (prefix) that will be used in the application to signal that the taglib is<br />

to be used. The format for the taglib directive is:<br />

<br />

The URI we specify can be abstracted from the physical location of the TLD,<br />

allowing us more flexibility and portability when deploying our Web applications.<br />

For example:<br />

<br />

The URI specified here is absolute, that is, it specifies a protocol, host, and uri.<br />

Within the web.xml file for our Web application, we must provide a taglib element<br />

to map this to a particular location. The location specifies a relative URI for the<br />

location of the TLD.<br />

Chapter 9. Using tag libraries 285

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

Saved successfully!

Ooh no, something went wrong!