aspose file tools*
The moose likes Other Application Frameworks and the fly likes Spring MVC Integration of  Tiles Complete Example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring MVC Integration of  Tiles Complete Example" Watch "Spring MVC Integration of  Tiles Complete Example" New topic
Author

Spring MVC Integration of Tiles Complete Example

Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 166
I just had success after a days hard work in integrating Tiles with Spring MVC.

Let me know if anyone need the example, I can paste the files here.


A Moment's insight is sometimes worth a Life's experience.
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
Hi Tauri,

I am looking for the code,can you paste here.
Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 166
Hey lemme know where you are stuck?
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
Hi Tauri,

Am in process of learning spring,expecting your code to know how Spring MVC need to be Integrated with Tiles.
Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 166
Here it goes..




springapp-Servlet.xml
======================


<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<!-- - Application context definition for "springapp" DispatcherServlet. -->

<beans>

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles-def.xml</value>
</list>
</property>
</bean>


<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>


<!-- URL Mappings -->
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true"/>

<property name="mappings">
<props>
<prop key="/example.htm">exampleController</prop>
</props>
</property>

<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor"/>
</list>
</property>
</bean>

<bean id="exampleController" class="test.ExampleController">
<property name="viewName" value="example"/>
</bean>

</beans>




web.xml\
=======


<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>



tiles-def.xml
=============


<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"<DTDURL>/tiles-config_2_0.dtd">



<tiles-definitions>


<!-- Components -->
<definition name="head-tile" path="/ui/head.jsp"/>
<definition name="left-nav-tile" path="/ui/leftnav.jsp"/>
<definition name="body-tile" path="/ui/body.jsp"/>
<definition name="foot-tile" path="/ui/foot.jsp"/>




<definition name="example" template="/WEB-INF/ui/layout.jsp">
<put-attribute name="body-tile" type="template" value="/WEB-INF/ui/body.jsp" />
<put-attribute name="head-tile" type="template" value="/WEB-INF/ui/head.jsp" />
<put-attribute name="left-nav-tile" type="template" value="/WEB-INF/ui/leftnav.jsp" />
<put-attribute name="foot-tile" type="template" value="/WEB-INF/ui/foot.jsp" />
</definition>



<definition name="SampleValidation" extends="example">
<put-attribute name="title" value="Hello Tile" />
</definition>


</tiles-definitions>



JSP's
======


Create a jsp for each panel - body,head,left and foot.
Create a layout.jsp where the layout of the page is defined.


layout.jsp:
===========


<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>


<html>
<head><title>OPM</title></head>

<body>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="2">
<tiles:insertAttribute name="head-tile"/>
</td>
</tr>
<tr>
<td width="25%">
<tiles:insertAttribute name="left-nav-tile"/>
</td>
<td width="75%">
<tiles:insertAttribute name="body-tile"/>
</td>
</tr>
<tr>
<td colspan="2">
<tiles:insertAttribute name="foot-tile"/>
</td>
</tr>

</table>
</body>


</html>
vidya sagar
Ranch Hand

Joined: Mar 02, 2005
Posts: 580
Thanks Tauri.
Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 166
Let me know if you have any issues.
Jason Rushton
Greenhorn

Joined: Aug 21, 2008
Posts: 2
I have been trying to find a good example of using Tiles as well. When I try and include the tag library:

<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>

I get an error saying it cannot be found. I am using the Eclipse IDE. Perhaps there is something that I am missing?
Jason Rushton
Greenhorn

Joined: Aug 21, 2008
Posts: 2
Nevermind I figured it out. I forgot to include the appropriate .jar file.
Johnny Gara
Ranch Hand

Joined: Mar 09, 2007
Posts: 43
Good job on getting this to work, there's not a lot of good examples on making Tiles2 working with Spring2.5+.
Tauri Valor
Ranch Hand

Joined: Aug 03, 2005
Posts: 166
Thanks Johnny. Im also trying to get the menus working with spring mvc.
Im trying to use menu-config to configure menus. Earlier I did it in struts long back, if you have any example please share with me.

I will complete it and show the complete example of Menus with Spring MVC here soon.
Anadi Misra
Ranch Hand

Joined: Jun 03, 2008
Posts: 69
Hi,

Has anyone tried with velocity?

I have a requirement to implement the composite view pattern with velocity templates. From where I have reached so far it appears I will have to extend a few classes from tiles-core, and may be spring framework too. But in case it is possible to get things working without that Please do let me know the solution.


Anadi Mishra.
Anadi Misra
Ranch Hand

Joined: Jun 03, 2008
Posts: 69
Hi,

Found a project that solved my worries

Spring-Tiles2-Velcoity

and lot of time too.
Peter Berghold
Greenhorn

Joined: Jun 30, 2008
Posts: 7
Originally posted by Tauri Valor:
Here it goes..


<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"<DTDURL>/tiles-config_2_0.dtd">



<tiles-definitions>


<!-- Components -->
<definition name="head-tile" path="/ui/head.jsp"/>
<definition name="left-nav-tile" path="/ui/leftnav.jsp"/>
<definition name="body-tile" path="/ui/body.jsp"/>
<definition name="foot-tile" path="/ui/foot.jsp"/>




<definition name="example" template="/WEB-INF/ui/layout.jsp">
<put-attribute name="body-tile" type="template" value="/WEB-INF/ui/body.jsp" />
<put-attribute name="head-tile" type="template" value="/WEB-INF/ui/head.jsp" />
<put-attribute name="left-nav-tile" type="template" value="/WEB-INF/ui/leftnav.jsp" />
<put-attribute name="foot-tile" type="template" value="/WEB-INF/ui/foot.jsp" />
</definition>



<definition name="SampleValidation" extends="example">
<put-attribute name="title" value="Hello Tile" />
</definition>


</tiles-definitions>



I take it the URL that you are pointing to display the page in the example you give here would be "SampleValidation"?

I'm trying to wrap my mind around what is going on here. I've used Tiles before but I've used the Struts framework with it and not Spring (yet.)


Peter L. Berghold Peter@Berghold.Net<br />Unix Professional IBM<br />"Those who fail to learn from history are condemned to repeat it."
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Peter, fyi, this thread seems to be a couple months old, and it might not get a reply from the OP. It might be better to just ask your question in a new thread.

Good Luck

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring MVC Integration of Tiles Complete Example
 
Similar Threads
Which template methods used mostly with Spring MVC
Spring Tiles
Spring / Tiles 2 example
struts2 Vs spring mvc
getting Request URL with spring mvc and tiles.