0

Spring 3.2tiles 3.0を使用しています。

このように、Spring Bean プロパティからタイル定義の属性の値を設定したい

<put-attribute name="headTitle" expression="${msgs['serviceGroups.title']}" />

msgs はHashMapであり、Spring アプリケーションコンテキストで定義されています

<bean id="msgs" class="qa.gov.moi.eservices.web.util.MessageSourceMapAdapter">
    <constructor-arg name="messageSource">
        <ref bean="messageSource"/>
    </constructor-arg>
</bean>

これは春のタイルの設定です

<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>

そしてこれはテンプレート default.jsp

<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

この問題を除いて、すべて問題ありません。

Spring Bean をタイル式にアクセスできるようにする方法はありますか?

4

1 に答える 1

0

問題はいくつかの小さな問題に分けられます。

1 - 1 つ目は、Bean へのtilesアクセスを有効にすることです。これは、Springspringコンテキスト Bean を Tiles ビューに公開することで実行できます - mck が提供するこれを確認してください。

2 - 2 つ目は、 で属性をレンダリングする方法です。値のないタグをJSP使用すると、タグが定義で提供された単純な値を使用してそれ自体をレンダリングし、使用する代わりに属性を完全に無視するため、スローされます。を評価できます。tiles:getAsStringput-attributeNullPointerExceptiontiles:getAsStringtoString()expressiongetAsStringinsertAttributeexpression

<!--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"/>
于 2013-06-07T14:34:01.957 に答える