访问定义文件中tiles 3表达式中的Spring 3 bean

访问定义文件中tiles 3表达式中的Spring 3 bean,spring,tiles,Spring,Tiles,我正在使用Spring3.2和tiles 3.0 我想从Springbean属性设置tiles定义中的属性值,如下所示 <put-attribute name="headTitle" expression="${msgs['serviceGroups.title']}" /> 除了这个问题,一切都好 有没有任何方法可以让SpringBean对tiles表达式进行访问 问题分为几个小问题: 1-第一个是启用tiles来访问springbean,这可以通过将spring上下文bean公

我正在使用Spring3.2和tiles 3.0

我想从Springbean属性设置tiles定义中的属性值,如下所示

<put-attribute name="headTitle" expression="${msgs['serviceGroups.title']}" />
除了这个问题,一切都好


有没有任何方法可以让SpringBean对tiles表达式进行访问

问题分为几个小问题:

1-第一个是启用
tiles
来访问
spring
bean,这可以通过将spring上下文bean公开到tiles视图来实现-由mck提供

2-第二个问题是如何在
JSP
中呈现属性,使用
tiles:getAsString
标记和
put属性
have-no-value将抛出
NullPointerException
,因为
tiles:getAsString
标记使用简单的
toString()
对定义中提供的值进行渲染,它将完全忽略
表达式
属性,而不是
getAsString
使用
insertAttribute
,它可以计算
表达式

<!--this works fine with expressions-->
<tiles:insertAttribute name="headTitle" ignore="true" />

<!-- and this will throw NullPointerException if value is not provided-->
<tiles:getAsString name="headTitle" ignore="true"/>

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles-defs.xml</value>
        </list>
    </property>
</bean>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title><tiles:getAsString name="headTitle"/></title>


</head>
<body>
    <div id="wrapper">
        <div id="container">
            <div id="top_header">
                <tiles:insertAttribute name="heading" />
                <tiles:insertAttribute name="menuTab" />
                <tiles:insertAttribute name="genralizationTab" />
            </div><!-- top_header -->
            <tiles:insertAttribute name="content" />
            <tiles:insertAttribute name="footer" />
        </div><!-- container -->
    </div><!-- wrapper -->
</body>
 Uncaught exception created in one of the service methods of the servlet /WEB-INF/jsp/layouts/default.jsp in application eservices. Exception created : java.lang.NullPointerException
<!--this works fine with expressions-->
<tiles:insertAttribute name="headTitle" ignore="true" />

<!-- and this will throw NullPointerException if value is not provided-->
<tiles:getAsString name="headTitle" ignore="true"/>