The Tiles Tag Library Tags


Using the Tiles Tag Library

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, your application's JSPs must declare their use of the library with a JSP taglib directive:

<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>

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"/>
Note 

Modern application servers use the uri attribute of the taglib directive to automatically resolve the location of the tag library descriptor file. Older application servers that support only JSP version 1.1 and/or version 1.0 require that tag libraries be registered in the web.xml file so that they can be resolved, as shown here:

<taglib>   <taglib-uri>http://struts.apache.org/tags-tiles</taglib-uri>   <taglib-location>/WEB-INF/tlds/struts-tiles.tld</taglib-location> </taglib>



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

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