Monday, October 04, 2004

Introducing SiteMesh

In my first post I introduced webwork, a nice MVC from OpenSymphony. It turns out that they have a few more projects worth looking at. SiteMesh is a very simple framework, yet very useful. Its purpose is to apply layout and decoration to a web application.
It works in a very simple way. SiteMesh is based on Servlet Filters and so it sits between the user's request and your web application. It is clearly separated from your web application, that isn't even aware it exists.
As your web application finishes a client's request, the resulting HTML is processed by SiteMesh. Custom layout and style is then applied, and finally the modified HTML is returned to the client's browser.
There are several situations that can take full advantage of this architecture:

  • You may need to choose from different layouts based on user's preferences (SiteMesh can choose decorators based on cookies, for example).
  • You can choose to have different style files applied, based on the user's browser or even language.
  • You may simply want to try out a different look for your application, before you actually make the changes visible to everyone else (you can define a decorator to be applied based on a specified request parameter).
With this kind of separation, your JSPs (or whatever you use for presentation) become simpler and hopefully won't need to be modified, if you want to change your application's look and feel.

0 comentários: