A story of getting the View layer up and running quickly in Spring…
Since the original article, parts of the code has been accepted upstream, now available as part of the Tiles-3 release, so the article has been updated — it’s all even simpler!
a web application’s view layer
with four simple steps using Spring and Tiles-3
to make organising large complex websites elegant with minimal of xml editing.
At FINN.no we were redesigning our control and view layers. The architectural team had decided on Spring-Web as a framework for the control layer due to its flexibility and for providing us a simpler migration path. For the front end we were a little unclear. In a department of ~60 developers we knew that the popular vote would lead us towards SiteMesh. And we knew why – for practical purposes sitemesh gives the front end developer more flexibility and definitely less xml editing.
But sitemesh has some serious shortcomings…
- from a design perspective the Decorator pattern can undermine the seperation MVC intends,
- requires all possible html for a request in buffer requiring large amounts of memory
- unable to flush the response before the response is complete,
- requires more overall processing due to all the potentially included fragments,
- does not guaranteed thread safety, and
- does not provide any structure or organisation amongst jsps, making refactorings and other tricks awkward.
One of the alternatives we looked at was Apache Tiles. It follows the Composite Pattern, but within that allows one to take advantage of the Decorator pattern using a ViewPreparer. This meant it provided by default what we considered a superior design but if necessary could also do what SiteMesh was good at. It already had integration with Spring, and the way it worked it meant that once the Spring-Web controller code was executed, the Spring’s view resolver would pass the model onto Tiles letting it do the rest. This gave us a clear MVC separation and an encapsulation ensuring single thread safety within the view domain.
Yet the best Tiles was going to give wasn’t realised until we started experimenting a little more…