facebook twitter youtube
by Amit Gupta - no comments

Tutorials in this series

  1. Quick jump with Spring 3 MVC – Theory apart : Covers spring MVC project setup
  2. Spring 3 MVC after a quick jump : Covers require spring annotations you use in controller, comparison with JAX-RS annotations, and many other request identifiers
  3. Basic Form Handling : How to handle a request and map it to a controller’s method. More about Model.
  4. Advanced Form handling : Handling multiple rows, binding multiple beans to a single form, uploading files etc.
  5. Basic Form validations
  6. Advanced Form Validation : custom validator and validating date field.

Why Tiles?

While developing a website you will notice many areas are repeated across all pages, like: header, footer, menu, contacts etc. You can design separate pages for them and can insert them in contents of other pages. You can call them as master pages as well.
Tiles provide a mechanism for this task. First you need to design a layout page where you can specify location of master pages and contents as below.


<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insertAttribute name="title" ignore="true" /></title>
<table border="1" cellpadding="2" cellspacing="2" align="center">
        <td height="30" colspan="2"><tiles:insertAttribute name="header" />
        <td height="250"><tiles:insertAttribute name="menu" /></td>
        <td width="350"><tiles:insertAttribute name="body" /></td>
        <td height="30" colspan="2"><tiles:insertAttribute name="footer" />

Somewhere you need to specify values for tiles attributes you used in above page.


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
    <definition name="base.definition"
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/WEB-INF/jsp/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/jsp/menu.jsp" />
        <put-attribute name="body" value="" />
        <put-attribute name="footer" value="/WEB-INF/jsp/footer.jsp" />

Each entry in tiles.xml is called definition. You can inherit a definition by another.

    <definition name="contact" extends="base.definition">
        <put-attribute name="title" value="Contact Manager" />
        <put-attribute name="body" value="/WEB-INF/jsp/contact.jsp" />

Attributes of contact definition will overwrite attribute’s values of base.definition.

Of course, you need to design all jsp pages.

Don’t forget to tell spring that you are using tiles framework.


<bean id="viewResolver"
    <property name="viewClass">
<bean id="tilesConfigurer"
    <property name="definitions">

source: viralpatel.net

However the original article written by Patel is very much explanatory, I just rewrote it in my way on one of the friend’s request.

Amit Gupta

Hey! this is Amit Gupta (amty). By profession, I am a Software Eng. And teaching is my passion. Sometimes I am a teacher, as you can see many technical tutorials on my site, sometimes I am a poet, And sometime just a friend of friends...

Leave a Reply