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.

Ads

Tutorials   
Struts 2.5.10.1 General Availability - released Login form in Struts2 version 2.3.16 Struts 2 Login Application Struts 2 version 2.3.16.3 released Struts 2 version 2.3.15.3 released Struts 2 Hello World Annotation Example Struts Roseindia Struts 2 Tutorial: Easy steps to learn Struts 2 Difference between Struts and Spring Apache Struts 2.3.15.2 launched to fix vulnerable Feature Struts2 Application in Eclipse: Running the application in Eclipse IDE Struts 2 Hello World Application using Eclipse Interceptors in Struts 2 Struts 2 Action Tag Struts 2 in Agile Development Environment Struts 2 UI Tags Generic Tags Creating own Interceptor What are Interceptors in Struts 2 and how do they work? Results Value Stack / OGNL Action in Struts 2 Framework Struts 2 Interceptors Struts 2.3.15.1 Maven - How to use Maven dependency of Struts 2.3.15.1? Download Struts 2.3.15.1 How Struts 2 Framework works? Architecture of Struts 2 Framework Features and Enhancements in Struts 2.3.15.1 Struts 2 Tutorials - Struts version 2.3.15.1 Struts 1 Tutorial and example programs Struts Tutorial What is Struts Struts Flow Diagram Step By Step Struts Tutorial Struts 2 Login Form Example Struts Video Tutorials Struts 2 Hello World Example Introduction to Struts 2 Framework Downloading and Installing Struts 2.3.8 In Struts What is Model? What is Struts? Download Struts What is Struts Framework? Struts Framework Latest Version of Struts Framework Downloading Struts Official example Struts 2.3.8 released with new features Struts 2.3.8 Tutorials and Examples Hibernate4 Struts Integration Struts2 Tiles Example
Ads

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.

     

Advertisements

Ads
Share on Google+Share on Google+

Using tiles-defs.xml in Tiles Application

Posted on: February 11, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Using tiles-defs.xml in Tiles Application   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
jsuresh
August 30, 2011
asdsadsds

http://www.roseindia.net/webpromothttp://www.roseindia.net/services/webdevelopement/web-developement-services.shtmlion/websubmission.shtmlhttp://www.roseindia.net/services/webdesigning/ Web Designing Web Redesigning Web Development Logo Design Web Design Packages Domain Registration Web Promotion Services SEO Services Search Eng. Optimization Search Eng. Submission SEO Tips SEO Portfolio Web Promotion Plans Content Development Content Development Article Writing Blog Writing News Writing SEO Copywriting Technical Documentation Article Marketing Web Hosting Services ASP.NET Hosting Unix Hosting E-Commerce Hosting Windows Hosting Hosting Plan E-Commerce Solutions CRM Home Privacy Policy © All Rights are Reserved for Rose India
maya
January 6, 2013
struts titles tutorial -- get error

when click on link in index.jsp get error: java.lang.IllegalArgumentException: Path Tiles.Example does not start with a "/" character

Ads

 

Ads