Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Using tiles-defs.xml in Tiles Application
Using tiles-defs.xml in Tiles Application Using tiles-defs.xml in Tiles Application In the last section we studied how to forward the request (call) to a jsp page which specifies which tiles layout definition should be used to apply to the
 
Search Tutorials:
 
Software Solutions and Services
 

 
Google Custom Search:
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation

Using tiles-defs.xml in Tiles Application

                         

In the last section we studied how to forward the request (call) to a jsp page which specifies which tiles layout definition should be used to apply to the content. In this section I will show you how to use the a definition in the tiles-defs.xml for generating the content. 

In Tiles we can define the definition in the tiles-defs.xml which specifies the different components to "plugin" to generate the output. This eliminates the need to define extra jsp file for each content file. For example in the last section we defined example.jsp to display the content of content.jsp file. In this section I will show you how to eliminate the need of extra jsp file using tiles-defs.xml file.

Steps to Use the tiles-defs.xml

Setup the Tiles plugin in struts-config.xml file.
Add the following code in the struts-config.xml (If not present). This enables the TilesPlugin to use the /WEB-INF/tiles-defs.xml file.
    
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
       <!-- Path to XML definition file -->
       <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
       <!-- Set Module-awareness to true -->
       <set-property property="moduleAware" value="true" />
</plug-in>

Defining the tiles-defs.xml
In this file we are defining the different components to "plugin". Here is the code:

     <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>

The name of the definition is Tiles.Example, we will use this in struts-config.xml (While creating forwards in struts-config.xml file) file. The page attribute defines the template file to be used and the put tag specifies the different components to "plugin". Your tiles-defs.xml should look like:

<?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
Open the struts-config.xml file and add the following code:

<action path="/Tiles/Example"
       forward="Tiles.Example"/>

With Tiles, the action points to the Tiles definition, as shown in the above code. In this code we are using the Tiles.Example definition which we have defined in the tiles-defs.xml file. Without Tiles, forward and action definitions point directly to JSPs. With Tiles, they point to the page's definition in the Tiles configuration file.

Testing the Application
Create a link in index.jsp to call the Example. Code added are: 

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

To test the application build it using ant and deploy on the JBoss server. Type http://localhost:8080/strutstutorial/index.jsp in the bowser and select the Using tiles-defs.xml link. Your browser should show the page.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

25 comments so far (
post your own) View All Comments Latest 10 Comments:

hi, i was trying to compile the struts application but so many errors are come, so i want to set the classpath for struts, where it is, pls help me...........

Posted by Suresh on Friday, 09.19.08 @ 16:43pm | #80525

I would like to Display dynamic content on alert box. Is it possible?

Posted by Amit Kumar Mishra on Thursday, 04.3.08 @ 18:28pm | #55235


Please give How to set CLASSPATH IN STRUTS TILE

THANK YOU

Posted by mahender on Saturday, 12.29.07 @ 17:50pm | #44137

if you set up your web.xml correctly with the taglibs you can do the following to use tiles defintions.

<%@ taglib uri="taglibs/struts-tiles" prefix="tiles"%>
<tiles:insert definition="your.layout" >
<tiles:put name="content" value="foo.jsp"/>
</tiles:insert>

Posted by muz on Tuesday, 10.16.07 @ 18:02pm | #34213

How to implements the stutsframe work in 'Eclipse'

Posted by K.Naga Krishna on Friday, 06.29.07 @ 08:02am | #20359

This is the best tutorial people really who wants to learn struts.step by step explination with examples makes to understand more easily.

Posted by sharon on Tuesday, 06.19.07 @ 17:11pm | #19706

its good book for beginers.

Posted by vidyadhar on Friday, 06.8.07 @ 21:12pm | #18625

How to use definations without creating defination for every single content pages.

Posted by bay1234 on Thursday, 05.31.07 @ 18:32pm | #17865

Hi,
I would like to use tiles for dynamic action, it means that I have 2 tiles template, each of them will set different action name to the JSP.
for example:
For mobile product I set the action
<definition name="mobile" template="/search.jsp">
<put name="actionName" value="/mobileSearch.do"/>
</definition>
For land line:
<definition name="land" template="/search.jsp">
<put name="actionName" value="/landSearch.do"/>
</definition>

in the jsp I set the action name like that:
<html:form action="<tiles:getAsString name="actionName"/>">
.
.
</html:form>
I got an exception.
How can I do that using tiles?
Is it possible?
Thanks,
Jaron

Posted by Jaron on Thursday, 05.10.07 @ 13:20pm | #15560

In Struts Tiles definition,we have to create our own tiles-def.xml file or it will be there in the project itself..Please do help on this

Posted by Leena on Friday, 03.30.07 @ 10:41am | #12968

Training Courses
Tell A Friend
Your Friend Name
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.