Nowadays, website are generally divided into pieces of reusable template that are being rendered among different web pages. For example a site containing header, footer, menu etc. This items remains same through out the website and give it a common look and feel. It is very difficult to hard code this in each and every webpage and if later a change is needed than all the pages needs to be modified. Hence we use templatization mechanism. We create a common Header, Footer, Menu page and include this in each page.
Tiles Plugin allow both templating and componentization. In fact, both mechanisms are similar: you
define parts of page (a “Tile”) that you assemble to build another part or a full page. A part can
take parameters, allowing dynamic content, and can be seen as a method in JAVA language.
The Tiles installation process depends on the Struts version you use. If you start a new project,
use the latest Struts version. Tiles can also be used without Struts.
Add following entry of plug-in tag to your struts-config.xml in order to configure Tiles.
In this entry you can see definitions-config parameter which is set to the value /WEB-INF/tiles-definitions.xml. So we have to create a file called tiles-definitions.xml in WEB-INF directory.
We will create a Header and a Footer that we will integrate with our sturts application. We will render this header and footer using Tiles.
Create two JSPs, Header.jsp and Footer.jsp and copy following content in it.
<divstyle="width: 100%; height: 200px; background-color: #ABBAF3"><h3>Tiles Plugin Example using Struts &amp;amp;amp; Eclipse</h3></div>
Layout.jsp file will define overall layout of web page. I have used a table based layout here. You can use a DIV based layout and align all the components using CSS.
Note that we have used a tag <tile:insert> in order to place the respective elements on this page. This will be more clear once you create tiles-definitions.xml file.
Now copy following code in tiles-plugins.xml file.