Spring MVC 3 and Apache Tiles 2.2.2 Integration

java

Apache Tiles is a popular templating framework used for Java web application. Tiles gain the popularity because Struts 1.x use Tiles as its default template framewrok. SpringMvc that is MVC framework just like Strust, also supports integration with Tiles as template framework.

In this tutorial we will go together to integrate SpringMvc 3 and Tiles 2.2.2. Remember, we use Tiles 2.2.2 although version 3 is ready.
The application we will make is like this:

ss aplikasi 1

Every menu in the left when it is clicked will change only the main part of the page (the center part). The old fashioned way to achieve this is using a number of pages that have same left side menu but different layout in the main part. But what happen if we have 100 pages and the footer has changed, we have to change all of the pages. What a waste of time.

I assume you have already know how to use SpingMVC 3

1. Configure The Library

The very first step is to install the needed libraries to the project.
libraries

2. Configure dispatcher-servlet.xml

3. Configure tiles.xml

In this configuration file we created one main layout and three partial pages. These partial pages will make our application has dynamic page.

4. JSP Code

layout.jsp

header.jsp

navigation.jsp

footer.jsp

welcome.jsp

createUser.jsp

listUsers.jsp

5. TilesController

Return String in the methods above refers to tiles name in the tiles.xml file.
Run the application and test the navigation menu.

Facebook Comments
 

Agung Setiawan

Agung Setiawan adalah software engineer di BukaLapak.com, penulis sekaligus pecinta sastra, dan pembaca buku

 
Halo, perkenalkan saya Agung Setiawan.
Saya Software Engineer di BukaLapak.
Simak pemikian saya soal dunia Software Engineering via Twitter di @agungsetiawanmu dan facebook
Blog ini saya update seminggu sekali jadi sering-sering saja mampir
Mau belajar Vim bareng saya?
Belajar ngoding dari nol menggunakan PHP

2 thoughts on “Spring MVC 3 and Apache Tiles 2.2.2 Integration

Leave a Reply

Your email address will not be published. Required fields are marked *