Jun 18th, 2010, 05:07 AM
FreeMarker Template Decorator
I am using Spring MVC coupled with FreeMarker as viewing technology in a current web project and was looking for an easy way to decorate all of my content pages with a default layout.
I had some previous experience with Tiles, but didn't like it because IMHO it's a little bit too invasive and too awkward to configure. Another option would have been to use SiteMesh, but again I didn't like the idea to setup an explicit servlet filter just to be able to decorate my views. Moreover, sharing of model data between the layout and the content pages would be rather complicated.
Fortunately, Spring MVC came to my rescue. It was actually quite easy to extend the existing FreeMarkerViewResolver and FreeMarkerView classes, so that view templates will be automatically decorated with a common layout page.
I thought it might be worthwhile to share the two classes (DecoratingFeeMarkerView and DecoratingFreeMarkerViewResolver - see attached zip). I've also included a sample spring config file to demonstrate how to configure the classes as well as a sample layout template and a sample content template page.
May 2nd, 2012, 02:55 AM
Last edited by xianglg; May 2nd, 2012 at 04:02 AM.
Tags for this Thread