I cannot display dynamic page title using spring 3 and apache tiles 2.2
I have a problem using spring 3 and tiles 2.2.2 . I can't display a dynamic page title. These are my config/jsp files:
layout.jsp
<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><tiles:getAsString name="title" ignore="true"/></title>
</head>
<body>
<tiles:insertAttribute name="header" />
<div id="content-outer">
<div id="content-wrapper" class="container_16">
<tiles:insertAttribute name="body" />
<tiles:insertAttribute name="menu" />
</div>
</div>
<tiles:insertAttribute name="footer" />
</body>
</html>
Spring config file:
<bean id="tilesviewResolver"
class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
<property name="order" value="0" />
<property name="requestContextAttribute" value="requestContext" />
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<bean id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="defin开发者_Python百科itions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
<property name="tilesProperties">
<props>
<prop key="org.apache.tiles.evaluator.AttributeEvaluator">org.apache.tiles.evaluator.el.ELAttributeEvaluator
</prop>
</props>
</property>
</bean>
tiles.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="base.definition" template="/WEB-INF/views/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/views/inc/header.jsp" />
<put-attribute name="menu" value="/WEB-INF/views/inc/menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/views/inc/footer.jsp" />
</definition>
<definition name="item/itemDetail" extends="base.definition">
<put-attribute name="title" value="%{title}"/>
<put-attribute name="body" value="/WEB-INF/views/item/itemDetail.jsp" />
</definition>
</tiles-definitions>
the page title isn't replaced with title value rendered by controller, instead %{title}.
Thanks in advance
I think that your page definition should look like this (note the 'expression' attribute and '$' instead of '%'):
<definition name="item/itemDetail" extends="base.definition">
<put-attribute name="title" expression="${title}"/>
<put-attribute name="body" value="/WEB-INF/views/item/itemDetail.jsp" />
</definition>
Are you sure that there is an attribute called ${title} in a relevant scope? Have you tried rendering the value of ${title} directly in the itemDetail.jsp page?
Here's the relevant documentation, tiles uses the servlet container's EL support for this: http://tiles.apache.org/2.1/framework/tutorial/advanced/el-support.html.
精彩评论