springmvc tiles3 - Spring MVC Tiles 3 integration tutorial

Spring MVC Tiles 3 integration tutorial

Posted on

springmvc tiles3 - Spring MVC Tiles 3 integration tutorial

One of the areas in which Spring MVC has advance compares to other frameworks is in the separation of view technologies. In this post, i will show how to integrate Apache Tiles 3 with Spring MVC. Apache Tiles is a free open-source template engine for java web frameworks. It’s based on Composite pattern and used to simplify the development of user interfaces.

Create a spring configuration XML file which add bean definition for TilesConfigurar and TilesView.

Now create a tiles definition xml file which contains tiles template definitions. I have created two xml files, one for tiles base template and another for tiles body definition but you can combine it in one.

Create a template jsp which include the common pages (like header, footer, menu etc.). I have used Blueprint css framework to create a grid for layout.




As you can see, In you main template jsp we have inserted body attribute but in tiles-def xml file that body attribute is blank. This is because spring controller will render this portion using its view rendering mechanism.

Create a Controller which has two action (index and viewPeson) . The return value of every controller will be mapped with each tiles definition which is associated with jsp to render as body in template.

A Person VO class just to show a list of person in personList.jsp.

Your second tiles defination xml (views.xml) will looks similar to following. Both the tile defination ‘index’ and ‘personList’ is extending ‘DefaultTemplate’.

tiles diagram - Spring MVC Tiles 3 integration tutorial




SpringMVC Tiles3 integration output - Spring MVC Tiles 3 integration tutorial

Download Source (without jars, size 63 kb)

Download WAR file (size 4.63 Mb)

Source techzoo.org