Using the Tiles Tag Library

 < Day Day Up > 



The Tiles Tag Library provides a set of tags that you can use to create Tiles-based page layouts. Also, as mentioned earlier in this chapter, with the Tiles tags, you can define Tiles definitions inside JSPs instead of (or in addition to) defining them in a Tiles XML configuration file.

To use the Tiles Tag Library in a Struts application, you need to include the following snippet in your application's Web Archive (.war) deployment descriptor, web.xml:

<taglib>   <taglib-uri>/WEB-INF/tlds/struts-tiles.tld</taglib-uri>   <taglib-location>/WEB-INF/tlds/struts-tiles.tld</taglib-location> </taglib> 

Recall from the overview of the web.xml file in Chapter 2 that the <taglib-uri> tag is used to declare the URI (or alias) that will be referenced in each of your JSPs with a taglib directive. The <taglib-location> tag is used to declare the actual location of the Tag Library Descriptor (.tld) file in your Web Archive.

The following snippet illustrates how your JSPs will declare their use of the Tiles Tag Library with a JSP taglib directive:

<%@ taglib uri="/WEB-INF/tlds/struts-tiles.tld" prefix="tiles" %>

Notice that the uri attribute specified here is the same as that declared with the <taglib-uri> tag in the web.xml file. Also, notice that the prefix attribute is set to tiles. This attribute can be set to whatever you want; however, tiles is the accepted default for the Tiles Tag Library. The prefix attribute declares the prefix that each tag must have when it is used in the JSP, as shown here:

<tiles:insert attribute="header"/>

Because tiles was defined as the prefix, the insert tag was used as shown. However, if you were to choose to use a prefix of strutstiles, the tag would be used as follows:

<strutstiles:insert attribute="header"/>



 < Day Day Up > 



Struts. The Complete Reference
Struts: The Complete Reference, 2nd Edition
ISBN: 0072263865
EAN: 2147483647
Year: 2003
Pages: 134
Authors: James Holmes

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net