Friday, January 11, 2008

Why SiteMesh instead of Tiles?

  1. SiteMesh is much easier to configure and use (less typing and easier to understand)
  2. Using Tiles, you need to have your forwards go to a "tiles page" versus the direct JSP. SiteMesh takes the approach that your page (your JSP) doesn't even know or care that it's being decorated.
  3. Using Tiles, each individual page you want to go to has to be associated with a layout - Major pain! Every time you create a new JSP that you want to forward to, you have to create another tiles definition and associate it with a layout and forward to the Tile page (versus the JSP). With SiteMesh you can simply set up a URL pattern and all your pages are decorated with the layout you choose.
On the other hand there is downside of using SiteMesh. SiteMesh stores the entire content of your HTML body into memory before it decorates it. If you have some very large pages, such as might happen in a reporting application where you don't have pagination implemented and end up with one large page of rows, you could end up with severe memory problems.
You can read this http://today.java.net/pub/a/today/2004/03/11/sitemesh.html post by Will Iverson about how to use SiteMesh.

5 comments:

  1. One way to overcome the sitemesh limitation is to create a two page sequence. Page one creates a AJAX or IFrame call back to page two, which in turn runs through the servlet to get the rest of the page. But with this approach you need to make sure that the second page you call won't get decorated. You don't want to decorate the content the second time around. In this way, the first page content is a light weight page and the second page does all the work. Also with this approach, you need to special attention to security. You don't want to create a hole where someone can maliciously scrape all your content from your database with modifying certain parameters and re-posting similar data to the servlet that renders the second page's call.

    ReplyDelete
  2. IIRC, SiteMesh can't not be used for portlets, while Tiles can be :-)

    ReplyDelete
  3. sitemesh is using the decorator pattern, which is considered slower than composite view pattern(tiles),in performance.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This article goes into a number of advantages Tiles-3 has over SiteMesh.

    Along with advantages the Composite pattern has over the Decorator pattern.

    the ultimate view – Tiles-3

    ReplyDelete