Home

This Chapter
-Chapter 12: The Tiles Framework
-The Problem with JSP Includes
-A Taste of Tiles
-Using JSP Definition Files
-Using XML Definition
-Inheritance of XML Definition
-The Tiles Tag Library’s Tags
-Writing Tiles XML Definition
-Summary

Table of Contents
-Introduction
-Chapter 1: Model 2 and Struts
-Chapter 2: Input Validation with Action Forms
-Chapter 3: The HTML Tag Library
-Chapter 4: Input Validation and Data Conversion
-Chapter 5: The Validator Plugin
-Chapter 6: The Expression Language
-Chapter 7: JSTL
-Chapter 8: The Bean Tag Library
-Chapter 9: The Logic Tag Library
-Chapter 10: Struts-EL, Nested, selectLabel
-Chapter 11: Message Handling and Internationalization
-Chapter 12: The Tiles Framework
-Chapter 13: Securing Struts Applications
-Chapter 14: The Config Object
-Chapter 15: The Persistence Layer
-Chapter 16: Object Caching
-Chapter 17: File Upload and File Download
-Chapter 18: Paging and Sorting
-Chapter 19: Preventing Double Submits
-Chapter 20: Early HttpSession Invalidation
-Chapter 21: Decorating Request Objects
-Chapter 22: How Struts Works

Previous
Next

 

Chapter 12

The Tiles Framework

Web applications need a consistent look, which you can achieve by using the same layout for all the pages. A typical layout has a header, a footer, a menu, an ad section, and a body content. Normally, many parts—such as the header, the footer, and the menu—look the same in all pages. To support component reuse, a common part can be implemented as an external resource. You then have a choice of using a frameset or a layout table to include these external resources. With a frameset, you reference each common external resource using a frame. If layout tables are being used, each JSP in your application will employ several include files: one for the header, one for the footer, one for the menu, one for the body content, and so on. The JSP technology provides the include directive (<%@ include %>, to include static files) and the include tag (<jsp:include>, to include dynamic resources) to make component reuse easy. However, as will be discussed in the first section of this chapter, both JSP includes are not without shortcomings. If the layout needs changing, you will have to change all your JSPs.

Tiles overcomes these failings and adds more features to enable you to lay out your pages more easily and flexibly. First and foremost, Tiles allows you to create a layout JSP that defines the layout for all the other JSPs in an application. Changes to a layout JSP will be reflected in all the JSPs referencing it. This means, only one page needs to be edited should the layout changes.

In addition to layout JSPs, Tiles allows you to write definition pages, which are more powerful than the former. A definition page can have one of the two formats, JSP and XML.

This chapter teaches you how to make full use of Tiles by presenting four sample applications that gradually introduce the features in Tiles. Afterwards, the complete list of tags in the Tiles Tag Library is given.

Note

The Tiles framework provides its services through a series of tags in the Tiles Tag Library. The classes that make up Tiles have been included in the struts.jar file, so there is no separate JAR file that you need to copy to your WEB-INF/lib directory. To reference the Tiles Tag Library’ tags indirectly, you need the struts-tiles.tld file in your WEB-INF directory and the following taglib element in your web.xml file.

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

Previous
Next