Tile Definitions - Create a Tile Definition


A layout may include many regions and we may have to repeat the parameter every time we want to use a tile layout, it would be better if we define it at one place instead of in each page.

We invoke the tile layout using tiles:insert and pass in parameters using tiles:put. The parameters are other JSP pages and strings that can be inserted into regions of the tile layout. We now need the ability to define default parameters corresponding to the common regions regions. The Tiles framework also lets you pass default arguments to a tile layout using definitions.

Create and use a JSP definition
First import the tiles tag library using the taglib directive.
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

Second ensure that the definition is defined only once using the logic:notPresent tag.
<logic:notPresent name="layoutDef" scope="application">

Third define the definition with the tiles:definition tag passing the JSP page that defines the tile layout and the scope of the newly defined definition.
<tiles:definition id="layoutDef" page="/layout.jsp" scope="application">

Fourth define the default parameters with the tiles:put tag.
<tiles:put name="title" type="string" value="DOG" />
<tiles:put name="header" value="/header.jsp" />
<tiles:put name="footer" value="/footer.jsp" />
<tiles:put name="content" type="string">
Some details...
</tiles:put>
</tiles:definition>
</logic:notPresent>

The tiles:definition tag defines a JavaBean component of type ComponentDefinition (org.apache.struts.tiles.ComponentDefinition). ComponentDefinition has getter and setters for all of the attributes that you can pass it. The logic:notPresent tag ensures that the ComponentDefinition is only created once per application by checking to see if it's already in scope before defining it.

Using a tile definition resembles using a tile layout directly. The only differences: you will specify the definition instead of the tile layout JSP page, and you will pass in less parameters with tiles:put.

 

Tiles tutorial
Introduction to Tiles
Web Page Layouts
JSP pages with embedded HTML
JSP pages with JSP include directive's (static) or JSP actions (dynamic)
JSP templates
Tiles
Layouts
Classic layout
Menu layout
Vertical box or vbox or vstack layout layout
Multi-columns layout
Center layout
Tabs layout
Installing Tiles
For Struts1.0
For Struts1.1
For Tiles stand alone
Configuring Tiles
Internationalizing Tiles
Create a Tile Layout
Use a Tile Layout
Create a Tile Definition
Use a Tile Definition

Use of this website constitutes acceptance of the AllAppLabs.com Terms and Conditions