8

我正在尝试在 Spring 3.1 中配置 apache tile 2.2.2 EL 支持。

根据瓷砖文档和我在谷歌上找到的内容,这应该可以工作,但它不会,相反,它会抛出 NullPointerException

瓷砖配置:

<bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
    <property name="order" value="1"/>
</bean>

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/views/**/views-def.xml</value>
        </list>
    </property>
    <property name="tilesProperties">
        <props>
            <prop key="org.apache.tiles.evaluator.AttributeEvaluator">
                org.apache.tiles.el.ELAttributeEvaluator
            </prop>
        </props>
    </property>
</bean>

简单的瓷砖定义:

<tiles-definitions>
    <definition name="temp.test" template="/WEB-INF/views/temp/test.jsp">
        <put-attribute name="test" expression="${test}" />
    </definition>
</tiles-definitions>

测试.jsp

<%--Works fine--%>
<h2>Called in jsp</h2>
<p>
    <c:out value="${test}"/>
</p>

<%-- throws NullPointerException --%>
<h2>Inserted from tiles</h2>
<p>
    <tiles:getAsString name="test"/>
</p>

cp 上的平铺库:

    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-api</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-core</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-jsp</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-template</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-el</artifactId>
        <version>2.2.2</version>
    </dependency>
4

2 回答 2

0

利用

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

代替

<!-- and this will throw NullPointerException if value is not provided-->
<tiles:getAsString name="test" ignore="true"/>
于 2013-06-07T14:40:48.293 回答
0

在玩 spring mvc 3.1.2.RELEASE 和 tile 2.2.2 时,空指针有类似的行为。检查您的 xerxesImpl 是否是最新的 2.9.1。还要检查您的 taglib,如前所述,还要检查您的日志记录。这些可以很好地协同工作:

<org.slf4j.version>1.5.8</org.slf4j.version>
    <log4j.version>1.2.16</log4j.version>
    <xercesImpl.version>2.9.1</xercesImpl.version>
    <org.springframework-version>3.1.2.RELEASE</org.springframework-version>
    <tiles.core.api.servlet.jsp.version>2.2.2</tiles.core.api.servlet.jsp.version>
于 2012-10-29T08:27:46.870 回答