sim085
Apr 27th, 2006, 09:26 AM
I am following the example from the book I have bought on how to implement Tiles in a Spring application (I removed all reference of FreeMarker for now).
Now this seems to partially be working, but not completely. So I have a default.ftl page inside the WEB-INF/tiles folder. I then created two other pages in the same folder called body.ftl and header.ftl.
I have a controller class names IntroController, this returns a new Model(“intro”, “message”, “hello”).
Now my tiles configuration is as follows:
<definition name="template" page="/WEB-INF/pages/default.ftl">
<put name="title" value="Default title"/>
<put name="header" value="="/WEB-INF/pages/header.ftl "/>
<put name="content" value="/WEB-INF/pages/intro.ftl"/>
</definition>
<definition name="intro" extends="template">
<put name="content" value="/WEB-INF/pages/intro.ftl"/>
</definition>
My default page is as follows:
<%@ taglib prefix="tiles" uri="/WEB-INF/lib/tiles/tiles.tld" %>
<html>
<head>
<title>
<tiles:getAsString name="title"/>
</title>
</head>
<body>
Testing!
<tiles:insert name="header"/>
<tiles:insert name="content"/> <tiles:insert name="footer"/>
</body>
</html>
The intro.ftl file only has written “Body” in it, and the header.ftl file only has “Header” in it (very simple).
Now I configured my tiles as follows in the application-servlet.xml:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles.TilesVi ew
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles.TilesCo nfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles-defs.xml</value>
</list>
</property>
</bean>
So as you can see from the above code I am not doing anything big. Now when I call my application I enter the URL http://localhost:8080/application/intro.htm. This goes in the IntroController which return the new ModelAndView. Since I have the tiles configuration the result goes to the definition with the name “intro”, this extends “template” so it goes up there and loads the page "/WEB-INF/pages/default.ftl".
This works fine, since this is the page I am getting, however on the screen I only have ‘Testing’ written (no ‘Header’ or ‘Body’). Also the title is set to ‘<tiles:getAsString name="title"/>’ and not ‘Default title’!
I went to see the source, and what I noticed is that what is happening is that the <tiles:insert . . . > and <tiles:getAsString . . . > are not being replaced.
I can not understand why this is happening, am not an expert in tiles, however I know I followed the book example till the last, even tried creating a control for the header section!
I am reading the other manning book struts in action the chapter related with tiles, but so far to no avail
Thanks for any help and suggestions,
Regards,
Sim085
Now this seems to partially be working, but not completely. So I have a default.ftl page inside the WEB-INF/tiles folder. I then created two other pages in the same folder called body.ftl and header.ftl.
I have a controller class names IntroController, this returns a new Model(“intro”, “message”, “hello”).
Now my tiles configuration is as follows:
<definition name="template" page="/WEB-INF/pages/default.ftl">
<put name="title" value="Default title"/>
<put name="header" value="="/WEB-INF/pages/header.ftl "/>
<put name="content" value="/WEB-INF/pages/intro.ftl"/>
</definition>
<definition name="intro" extends="template">
<put name="content" value="/WEB-INF/pages/intro.ftl"/>
</definition>
My default page is as follows:
<%@ taglib prefix="tiles" uri="/WEB-INF/lib/tiles/tiles.tld" %>
<html>
<head>
<title>
<tiles:getAsString name="title"/>
</title>
</head>
<body>
Testing!
<tiles:insert name="header"/>
<tiles:insert name="content"/> <tiles:insert name="footer"/>
</body>
</html>
The intro.ftl file only has written “Body” in it, and the header.ftl file only has “Header” in it (very simple).
Now I configured my tiles as follows in the application-servlet.xml:
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="viewClass">
<value>
org.springframework.web.servlet.view.tiles.TilesVi ew
</value>
</property>
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles.TilesCo nfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles-defs.xml</value>
</list>
</property>
</bean>
So as you can see from the above code I am not doing anything big. Now when I call my application I enter the URL http://localhost:8080/application/intro.htm. This goes in the IntroController which return the new ModelAndView. Since I have the tiles configuration the result goes to the definition with the name “intro”, this extends “template” so it goes up there and loads the page "/WEB-INF/pages/default.ftl".
This works fine, since this is the page I am getting, however on the screen I only have ‘Testing’ written (no ‘Header’ or ‘Body’). Also the title is set to ‘<tiles:getAsString name="title"/>’ and not ‘Default title’!
I went to see the source, and what I noticed is that what is happening is that the <tiles:insert . . . > and <tiles:getAsString . . . > are not being replaced.
I can not understand why this is happening, am not an expert in tiles, however I know I followed the book example till the last, even tried creating a control for the header section!
I am reading the other manning book struts in action the chapter related with tiles, but so far to no avail
Thanks for any help and suggestions,
Regards,
Sim085