Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Developing Simple Struts Tiles Application

Developing Simple Struts Tiles Application Developing Simple Struts Tiles Application Introduction In this section I will show you how to develop simple Struts Tiles Application. You will learn how to setup the Struts Tiles and create example

Tutorial Details:

page with it.
What is Struts Tiles?
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. 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.
Steps To Create Tiles Application
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
Tiles can can be used with or without Struts. Following entry is required in the web.xml file before you can use the tiles tags in your application.

/tags/struts-tiles
/WEB-INF/struts-tiles.tld

Create layout JSPs.
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 ):
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>


<tiles:getAsString name="title" ignore="true"/>
















We have defined the structure for web application using the appropriate html and did the following things:
Referenced the /WEB-INF/struts-tiles.tld TLD.
Used the string parameters to display title using the tiles:getAsString tag. If the attribute ignore="true" then Tiles ignore the missing parameter. If this is true then the Tiles framework will through the exception in case the parameter is missing.
To insert the content JSP, the tiles:insert tag is used, which inserts any page or web resources that framework refers to as a title. For Example inserts the header web page.
Develop the web pages using layouts
Now we will use tile layout create a page to display the content page in the in our application. For every content page there is additional jsp file for inserting the content in the Layout, so we have to create two jsp files one for content and another for displaying the content. In our example these file are example.jsp and content.jsp. Here is the code for both the files:
content.jsp

Welcome to the Title Tutorial


This is the content page


The content.jsp simply define the content of the page. The content may be dynamic or static depending on the requirements.
example .jsp
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>







The code specifies the tiles layout page to be used. We have set the flush attribute to true, this makes the tile file to be written to browser before the rest of the page. To specify the title of the page is used. The following code is used to insert the actual pages in the template.:




The top.jsp will be inserted in the layout's header region. The left.jsp will be inserted in the layout's menu region. The content.jsp wil be inserted in the layout's body region and the bottom.jsp will be inserted in the bottom region.
Repackage, run and test application
Add the following code in the index.jsp to test the this tile example:

  • Tiles Example


    Example of creating first tile application.

  • Use the ant tool to build the application and deploy on the server. To test the application go to the index.jps and click on the Tiles Example link.


     

    Rate Tutorial:
    http://www.roseindia.net/struts/struts_tiles.shtml

    Read Tutorial at: Click here to view the tutorial

    Rate Tutorial:
    Developing Simple Struts Tiles Application

    View Tutorial:
    Developing Simple Struts Tiles Application

    Related Tutorials:

    UI design with Tiles and Struts
    UI design with Tiles and Struts
     
    Boost Struts with
    Boost Struts with XSLT and XML
     
    Mix protocols transparently in Struts
    Mix protocols transparently in Struts
     
    Jump the hurdles of Struts development
    Jump the hurdles of Struts development
     
    Excellent tutorial on Struts and Tiles
    Excellent tutorial on Struts and Tiles This tutorial assumes knowledge of Java, JDBC, Servlets, J2EE (with regards to Web applications) and JSP Struts in a holistic manner, minus the beads and crystals. The Tiles framework makes creating reusable pages
     
    Struts best practices
    Multiple options are available for solving problems with Struts. When deciding among these alternatives, the choice must be based on parameters such as the scale of work and availability of time.
     
    Integrating Struts, Tiles, and JavaServer Faces
    Integrating Struts, Tiles, and JavaServer Faces. Bring the power, flexibility, and manageability of the three technologies together.
     
    Reuse Tiles and Simplify UI
    JavaServer Pages (JSP) technology supports application object reuse through includes, which allow other files (including other JSPs) to be sourced into a JSP file either at compile time or dynamically at application runtime. This is great for abstracting
     
    Programming Jakarta Struts: Using Tiles, Part 2
    In part two in this series of book excerpts on using tiles from Programming Jakarta Struts, learn how to install and configure tiles, as well as get an overview on tiles.
     
    Developing Simple Struts Tiles Application
    In this tutorial I will show you how to develop simple Struts Tiles Application. You will learn how to setup the Struts Tiles and create example page with it.
     
    Struts and Tiles aid component-based development
    In the Java world, Struts is one of the best-known and most talked about open source embodiments of MVC.
     
    Using tiles-defs.xml in Tiles Application
    In this lesson you will learn how to define and use the "plugin" definitation in tiles-defs.xml file.
     
    Open Source Web Frameworks in Java
    Open Source Web Frameworks in Java Open Source Web Frameworks in Java Struts Struts Frame work is the implementation of Model-View-Controller (MVC) design pattern for the JSP. Struts is maintained as a part of Apache Jakarta project and is open
     
    Jakarta Struts Interview Questions
    Jakarta Struts Interview Questions Jakarta Struts Interview Questions Q: What is Jakarta Struts Framework? A: Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications.
     
    Client Side Address Validation in Struts
    Client Side Address Validation in Struts Client Side Address Validation in Struts In this lesson we will create JSP page for entering the address and use the functionality provided by Validator Framework to validate the user data on the browser.
     
    Beginner to advance guide to the Apache Struts
    Beginner to advance guide to the Apache Struts The Complete Apache Struts Tutorial This complete reference of Jakarta Struts shows you how to develop Struts applications using ant and deploy on the JBoss Application Server. Ant script is provided
     
    Struts Guide
    Struts Guide Struts Guide This tutorial is extensive guide to the Struts Framework. In this tutorial you will learn how to develop robust application using Jakarta Struts Framework. This tutorial assumes that the reader is familiar with the web
     
    Developing Simple Struts Tiles Application
    Developing Simple Struts Tiles Application Developing Simple Struts Tiles Application Introduction In this section I will show you how to develop simple Struts Tiles Application. You will learn how to setup the Struts Tiles and create example
     

    Understanding Struts Action Class In this lesson I will show you how to use Struts Action Class and forward a jsp file through it. What is Action Class? The Action Class is part of the Model and is a wrapper around the business logic. The purpose
     
    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
     
    Site navigation
     

     

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

    Copyright © 2006. All rights reserved.