Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring MVC Integration of Tiles Complete Example

 
Tauri Valor
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tauri,

I am looking for the code,can you paste here.
 
Tauri Valor
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey lemme know where you are stuck?
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tauri.
 
Tauri Valor
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me know if you have any issues.
 
Jason Rushton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind I figured it out. I forgot to include the appropriate .jar file.
 
Johnny Gara
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Misra
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Found a project that solved my worries

Spring-Tiles2-Velcoity

and lot of time too.
 
Peter Berghold
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic