Apache tiles EL support in Spring 3
Asked Answered
H

2

8

I'm trying to configure apache tiles 2.2.2 EL support in Spring 3.1.

According to tiles documentation and from what I've found on google, this should work, but it doens't, instead, it throws NullPointerException

Tiles config:

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

Simple tiles definition:

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

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

Tiles libraries on 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>
Hugohugon answered 25/1, 2012 at 4:57 Comment(2)
Did you add <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%> in the beginning of jsp file? Can you be more precise about NullPointerException - post full stacktrace?Kalpa
Agreed with @Xaerxess. Could you post your entire JSP and the stack trace of your NPE?Braley
V
0

use

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

instead of

<!-- and this will throw NullPointerException if value is not provided-->
<tiles:getAsString name="test" ignore="true"/>
Vanscoy answered 7/6, 2013 at 14:40 Comment(0)
P
0

Had similar behavior with null pointer while playing with spring mvc 3.1.2.RELEASE and tiles 2.2.2. Check your xerxesImpl if is the latest 2.9.1. Also check your taglib as mentioned earlier also check your logging. These work fine together:

<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>
Perforation answered 29/10, 2012 at 8:27 Comment(0)
V
0

use

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

instead of

<!-- and this will throw NullPointerException if value is not provided-->
<tiles:getAsString name="test" ignore="true"/>
Vanscoy answered 7/6, 2013 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.