Tiles 2 + Spring: Attribute not found

marioosh picture marioosh · Jul 21, 2011 · Viewed 7.7k times · Source

I'm working on integrating Tiles 2 with Spring, but have a problem. I have a simple tiles.jsp page. Rendering tiles view produce error: org.apache.tiles.template.NoSuchAttributeException: Attribute 'title' not found.My configuration and files below.

Tiles config:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:order="1">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/pages/" />
    <property name="suffix" value=".jsp" />
</bean>
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="0">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
    <property name="prefix" value="/WEB-INF/pages/" />
    <property name="suffix" value=".jsp" />
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/defs/templates.xml</value>
        </list>     
    </property>
</bean>

Definitions in /WEB-INF/defs/templates.xml:

<tiles-definitions>
    <!-- Default Main Template -->
    <definition name="base" template="/WEB-INF/pages/tiles.jsp">
        <put-attribute name="title" value="Empty" type="string" />
        <put-attribute name="header" value="/WEB-INF/tiles-templates/header.jsp" />
        <put-attribute name="footer" value="/WEB-INF/tiles-templates/footer.jsp" />
        <put-attribute name="body" value="/WEB-INF/tiles-templates/blank.jsp" />
    </definition>
    <definition name="tiles" extends="base">
        <put-attribute name="title" value="Simple Tiles 2 Example"/>
    </definition>
</tiles-definitions>

Controller:

@Controller
public class MainController {

    @RequestMapping("/tiles")
    public String tiles() {
        return "tiles";
    }
}

/WEB-INF/pages/tiles.jsp:

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

<html>
<head>
    <title><tiles:getAsString name="title" /></title>
    <link rel="stylesheet" type="text/css" href="<c:url value="/css/main.css"/>" />
</head>
<body>
    <div id="header">
       <div id="headerTitle"><tiles:insertAttribute name="header" /></div>
    </div>
    <div id="content">
       <tiles:insertAttribute name="body" />
    </div>
    <div id="footer">
       <tiles:insertAttribute name="footer" />
    </div>
</body>
</html>

Answer

marioosh picture marioosh · Jul 21, 2011

Resolved! I've removed suffix and prefix properties from tilesViewResolver and everything began work.

<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="0">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>