Apache Tiles Tiles Introduction l l l Tiles

  • Slides: 16
Download presentation
Apache Tiles

Apache Tiles

Tiles Introduction l l l Tiles is a framework for the development user interface

Tiles Introduction l l l Tiles is a framework for the development user interface Tiles is enables the developers to develop the web applications by assembling the reusable tiles (jsp, html, etc. . ) Tiles uses the concept of reuse and enables the developers to define a template for the web site and then use this layout to populate the content of the web site

Tiles Introduction l For example, if you have to develop a web site having

Tiles Introduction l For example, if you have to develop a web site having more that 500 page of static content and many dynamically generated pages. The layout of the web site often changes according to the business requirement. In this case you can use the Tiles framework to design the template for the web site and use this template to populate the contents. In future if there is any requirement of site layout change then you have to change the layout in one page. This will change the layout of you whole web site.

Tiles 1 and Tiles 2 l l l Tiles has been designed to use

Tiles 1 and Tiles 2 l l l Tiles has been designed to use with the Struts Framework Tiles can be used with or without Struts. Tiles which has been design to use with out Struts is called as Tiles 2

Steps To Create Tiles Application l Tiles is very useful framework for the development

Steps To Create Tiles Application l Tiles is very useful framework for the development of web applications. Here are the steps necessary for adding Tiles to your Struts application – – Add the Tiles Tag Library Descriptor (TLD) file to the web. xml. Create layout JSPs. Develop the web pages using layouts. Repackage, run and test application.

Add the Tiles TLD to web. xml file l <taglib> <taglib-uri>/tags/struts-tiles</taglib-uri> <taglib-location>/WEB-INF/struts-t iles. tld</taglib-location>

Add the Tiles TLD to web. xml file l <taglib> <taglib-uri>/tags/struts-tiles</taglib-uri> <taglib-location>/WEB-INF/struts-t iles. tld</taglib-location> </taglib>

Create layout JSPs. l Our web application layout is divided into four parts: To

Create layout JSPs. l Our web application layout is divided into four parts: To Banner, Left Navigation Bar, Content Area and Bottom of the page for copy right information. Here is the code for out template (template. jsp):

template. jsp l <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-tiles. tld" prefix="tiles" %> <html>

template. jsp l <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-tiles. tld" prefix="tiles" %> <html> <head> <title><tiles: get. As. String name="title" ignore="true"/></title> </head> <body> <table border="1" cellpadding="0" cellspacing="0" width="100%" bordercolor="#000000" bgcolor="#E 7 FDFE"> <tr> <td width="100%" colspan="2" valign="top"><tiles: insert attribute="header"/></td> </tr> <td width="23%"><tiles: insert attribute="menu"/></td> <td width="77%" valign="top"><tiles: insert attribute="body"/></td> </tr> <td width="100%" colspan="2" valign="top"><tiles: insert attribute="bottom"/></td> </tr> </table> </body> </html>

example. jsp l <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-tiles. tld" prefix="tiles" %> <tiles:

example. jsp l <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts-tiles. tld" prefix="tiles" %> <tiles: insert page="/tiles/template. jsp" flush="true"> <tiles: put name="title" type="string" value="Welcome" /> <tiles: put name="header" value="/tiles/top. jsp" /> <tiles: put name="menu" value="/tiles/left. jsp" /> <tiles: put name="body" value="/tiles/content. jsp" /> <tiles: put name="bottom" value="/tiles/bottom. jsp" /> </tiles: insert>

Repackage, run and test application l <li> <html: link page="/tiles/example. jsp">Tiles Example</html: link> Example

Repackage, run and test application l <li> <html: link page="/tiles/example. jsp">Tiles Example</html: link> Example of creating first tile application. </li>

Steps to Use the tiles-defs. xml l Add the following code in the struts.

Steps to Use the tiles-defs. xml l Add the following code in the struts. xml, This enables the Tiles. Plugin to use the /WEB-INF/tiles-defs. xml file. l <plug-in class. Name="org. apache. struts. tiles. Tiles. Plugin" > <!-- Path to XML definition file --> <set-property="definitions-config" value="/WEBINF/tiles-defs. xml" /> <!-- Set Module-awareness to true --> <set-property="module. Aware" value="true" /> </plug-in>

Defining the tiles-defs. xml l <? xml version="1. 0" encoding="ISO-8859 -1" ? > <!DOCTYPE

Defining the tiles-defs. xml l <? xml version="1. 0" encoding="ISO-8859 -1" ? > <!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 1. 1//EN" "http: //jakarta. apache. org/struts/dtds/tiles-config_1_1. dtd"> <tiles-definitions> <definition name="Tiles. Example" page="/tiles/template. jsp"> <put name="title" type="string" value="Welcome" /> <put name="header" value="/tiles/top. jsp" /> <put name="menu" value="/tiles/left. jsp" /> <put name="body" value="/tiles/content. jsp" /> <put name="bottom" value="/tiles/bottom. jsp" /> </definition> <definition name="${YOUR_DEFINITION_HERE}"> </definition> </tiles-definitions>

Configure the Struts Action to use Tiles Definition l Open the struts. xml file

Configure the Struts Action to use Tiles Definition l Open the struts. xml file and add the following code: l <action path="/Tiles/Example" forward="Tiles. Example"/>

Testing the Application l <li> <html: link page="/Tiles/Example. do">Using tiles-defs. xml</html: link> Example shows

Testing the Application l <li> <html: link page="/Tiles/Example. do">Using tiles-defs. xml</html: link> Example shows you how to use tiles-defs. xml file. </li>

For Your Reference l l http: //tiles. apache. org/tutorial/index. html http: //tiles. apache. org/

For Your Reference l l http: //tiles. apache. org/tutorial/index. html http: //tiles. apache. org/ http: //www. laliluna. de/tutorial/firsttiles/first_struts_tiles_tutorial. pdf http: //www. roseindia. net/struts_tiles. sht ml

Thank You

Thank You