A free open-sourced templating framework for modern Java applications. Based upon the Composite pattern it is built to simplify the development of user interfaces.
For complex web sites it remains the easiest and most elegant way to work alongside any MVC technology.
What is Tiles?
Tiles is a view layer framework for Java EE applications that allows to separate pages into reusable pieces, according to the Composite View design pattern.
Who is the creator of Tiles?
Tiles has been created by Cédric Dumoulin, who had the idea and integrated it into Struts.
Why Tiles has this name?
We did not ask Cédric, but I think that he thought about tiling the pages. A tile here, a tile there, and you have your page complete
Where do I start learning Tiles?
First of all you have to get started. Then check out the Tutorial
How do I get support for Tiles?
You can subscribe to the users mailing list and ask your questions there.
How can I contribute?
Contributions and patches are easiest done via github.
I received an ""Attribute 'name' not found." exception. What's that?
Probably you forgot to fill an attribute of a template, or you are forwarding directly to a template page with at least an attribute.
Template with attributes cannot be forwarded alone without filling their attributes. Either create a definition, or fill manually the attributes in the attribute context.
I received a NoSuchDefinitionException, but I am sure that the definition is correct. What happened?
Usually it is a problem in loading definitions. See the startup of your application: you'll probably see an exception stack trace. That is the "real" problem.
Can I have a "definition in a definition"? How can I do it?
Yes. See Nesting and extending.
I filled an attribute of a template, but it did not get in an inner template. What happened?
Attributes must be filled in the correct template. In other words, there are no "pass-through" attributes, that you fill in the master template and get filled in the inner ones.
In this case, usually you have to create a new definition extending from an existing one, fill the attribute in the correct template and assign the new definition as an attribute to the main template.
How do I refresh a single tile without changing the other ones?
You are getting confused between frames and tiles. Although frames and tiles can be combined, in general tiles are used in place of frames. In this case the server combines all the tiles into a single web page (without any frames), so you can't refresh just one tile. You have to refresh the whole page
Is Tiles2 compatible with the version of tiles I've been using with Struts?
No. Struts-Tiles is an ancestor of Tiles 2 which grew out of the Struts project. This version is a total redesign which makes the framework easier to embed within frameworks such as Struts and Shale.
If you're a casual user, you'll probably only notice the differences in the tag libraries and in Tiles definition files. Many of them have been renamed for clarity sake and you can upgrade to Tiles2 by simple doing a global find and replace.
If you're integrating Tiles into a framework or using it for more advanced features, then you'll probably notice a world of difference. Tiles now runs as a container which encapsulates it's feature set and there is a much cleaner API. If you find that this api doesn't suffice for you, please hop on the developer list and help us flush out the next generation of Tiles!
How can I migrate from Struts-Tiles?
We have prepared a Migration guide.
Why should I move from Struts-Tiles to Tiles 2?
Tiles 2 can be used outside of Struts: it has been integrated into Struts 1, Struts 2 and Shale. And Tiles 2 is supported by a passionate team.
Why did you change everything in Tiles 2?
To improve learning of Tiles. After the refactoring, the APIs, the TLD and the DTD are clearer than before.
The Composite View Pattern
All websites have something in common: they are made of pages that share similar structures. The pages share the same layout, while each page is made of different independent pieces, but always placed in the same position across all the site.
The Composite View pattern formalizes this typical use, by allowing to create pages that have a similar structure, in which each section of the page vary in different situations.
How the pattern works
To understand this pattern, let's take an example. In the following picture you can see a typical structure of a web page
This structure is called "Classic Layout". The template organizes the page according to this layout, putting each "piece" in the needed place, so that the header goes up, the footer down, etc.
It can happen that, for example clicking on a link, it is needed to change only a part of the page, typically the body.
As you can see, the pages are different, but their difference is only in the body part. Note that, however, the pages are distinct, it is not like a refresh of a frame in a frameset!
Using the composite view pattern, the other part of the page have been reused, and the layout consistence has been preserved.
The role of the View Helper
Each piece of the composed page can have a "view helper". This pattern allows the preparation of the data to be displayed in a consistent way for the page piece itself, for example to create a menu
Composite View vs. Decorator
Tiles is a composite view framework: it allows to reuse page pieces across the application. But another approach to achieve the same result is using the Decorator pattern. For example, Sitemesh is based on the Decorator pattern.
Instead of creating a template and organizing the pieces together, the Decorator pattern (in this case) takes a simple HTML page, transforms it adding the missing pieces (in our example, adding header, footer and menu) and finally renders it.
Here you can find a comparison table between the two patterns.
Lets design struts 2 web application without tiles in eclipse.
jars required – add following jars into build path of ecipse
Project Preview in eclipse
< %@ page language="java" contentType="text/ html; charset=ISO-8859-1"
< ! DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html >
< head >
< meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
< title > LoginPage < / title >
< / head >
< body >
< br > < br > < br > < br > < br > < br >
< center >
< form action="login.action" >
UserName : < input type="text" name="uname" > < br > < br >
Password : < input type="password" name="pass" > < br> < br >
< input type="submit" value="Login" >
< / form >
< / center >
< / body >
< / html >