Académique Documents
Professionnel Documents
Culture Documents
Tiles is used to create reusable presentation components. With Tiles, we first define a base layout with different sections after that we define which jsp page should fill in the corresponding regions in an exteranl configuration file. The same layout can be reused any number of times by specifying different jsp pages.
The developer have two alternative ways to create the layout. He add the header and footer to each page of the site or he use the command <jsp:include>, to include the header and footer into the pages. In the first way all pages contains the header and footer source code. When the header or footer will changed, the developer have to change all pages. In the second way the header and footer are placed in seperated files, so the files can be included into the pages where they will be needed. When he change the layout and add a menu to the library application, shown by the picture below, the developer have to change all pages, because he have to add the inlude command of the menu in each page. On this situation tiles is the best way to develope the page layout, thus the developer don`t have to change each page.
Tiles use a seperate layout file, that contains the container of the layout. When the layout will be changed only the layout file and the tiles configuration files have to change by the developer. That will save many time on large applications.
jsp:include action:
The <jsp:include> element allows you to include either static and dynamic files in a JSP file. The results of including static and dynamic files are quite different. If the file is static, its content is included in the calling JSP file. If the file is dynamic, it acts on a request and sends back a result that is included in the JSP page. When the include action is finished, the JSP container continues processing the remainder of the JSP file. <jsp:include> element handles both types of files, so it is convenient to use when you dont know whether the file is static or dynamic.
Example:
<html> <head> <title>demo of jsp include</title> </head> <body bgcolor="#551a8b"> <center>What is new Jsp. </center> <p> These are include pages<ol> <li><jsp:include page="step1.html" <li><jsp:include page="step2.html" <li><jsp:include page="step3.html" <li><jsp:include page="step4.html" </ol> </body> </html>
xml. 6. Elimination of duplicate and redundant information Tiles eliminate the duplicate and redundant information in the configuration file by providing Tiles inheritance. 7. Central location for view components Tiles save definition of all the components at one place (in tilesDef.xml) and hence can be modified easily when required.
Disadvantages of Tiles 1. Increases the number of pages 2. Increases complexity Tiles increase complexity by introducing another layout page. Understanding and implementing templating can also be difficult at initial stages. 3. Big API Tiles have a bigger API set which may be difficult to understand for getting full benefit of tiles. 4. You have to specify a name to any component you create.
Add following entry of plug-in tag to your struts-config.xml in order to configure Tiles. <plug-in className="org.apache.struts.tiles.TilesPlugin"> <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" /> <set-property property="moduleAware" value="true" /> <set-property property="definitions-parser-validate" value="true" /> </plug-in>