views:

215

answers:

1

In Struts2, how do you share your common html across all pages?

In Asp.net, you've got Master pages, and in Rails there are Layouts. The idea is that your common html (eg the header, menu, and styles) are all easy to maintain because they are in one place, but for the life of me i can't find the equivalent feature in Struts2.

Is it called something else, or something, is that why i can't find it?

+1  A: 

I have used both Tiles2 and SiteMesh to accomplish this.

Tiles is configuration based where you define pages and their structure (usually in xml)

SiteMesh is based on decorators where you have a template that is applied through a filter to the resulting page. SiteMesh uses more memory on the server side because of the re-styling done in the filter, so the html of the result page must be parsed and applied.

smokeysonora
Tiles info: http://tiles.apache.org/framework/tutorial/basic/concepts.html
smokeysonora
SiteMesh info: http://www.opensymphony.com/sitemesh/
smokeysonora
The tiles website says the it is now integrated into struts2... that sounds like the way to go. Thanks. So is tiles basically a struts2 plugin?
Chris
Here's the struts info on tiles: http://struts.apache.org/2.1.8/docs/tiles-plugin.html
Chris
So which is better / easier / nicer in your experience? Tiles or sitemesh?
Chris
They each have a place really. I like sitemesh because it basicly takes the "body" section of your jsp and applies the style around it. This means that you can work with complete HTML pages in development then the sitemesh styling will add in / replace any CSS / javascript with the defaults.tiles you work a lot with fragments of pages.Tiles is faster and uses less memory.Tiles has built in features like permissions / roles tied into a tile so you can leverage that to hide sections of pages based on role.
smokeysonora
Thanks for the advice. I'll start with sitemesh then and use it until i hit its limitations.
Chris