开发者

Using Velocity with Tiles and Spring

开发者 https://www.devze.com 2023-01-23 15:14 出处:网络
I\'m presently using Spring 3.0.4 and Apache Tiles 2.2.2 in my web app. I\'d like to replace JSP with Apache Velocity 1.6.3 but I\'m somewhat confused on how to do this. Ultimately, I\'d like to be ab

I'm presently using Spring 3.0.4 and Apache Tiles 2.2.2 in my web app. I'd like to replace JSP with Apache Velocity 1.6.3 but I'm somewhat confused on how to do this. Ultimately, I'd like to be able to do the following in a Tiles definition:

<definition name="basicLayout" template="/WEB-INF/layout/basicLayout.vm">
    <put-attribute name="header" value="/WEB-INF/layout/header.vm" />
    <put-attribute name="content-area" value="/WEB-INF/layout/content.vm" />
    <put-attribute name="footer" value=开发者_高级运维"/WEB-INF/layout/footer.vm" />
</definition>

Is this possible? If so, do I need to create any custom view classes to support it? I'm currently using the standard Spring VelocityConfigurer, TilesConfigurer, VelocityView, TilesView classes.

Thanks!


I've created helper classes which include tiles integration with velocity: https://github.com/pete911/openhouse-web there's a descritption when you scroll down. classes can be found in maven central as well.


inside your servlet definition you need the following:

    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass">
        <value>
            org.springframework.web.servlet.view.tiles2.TilesView
    </value>
    </property>
</bean>
<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles.xml</value>
        </list>
    </property>
</bean>

as you can see you declare tiles.xml ..this is the file that will hold the definiotion name etc.

if you are using maven you need the following dependencies:

<dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-api</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-core</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-jsp</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-servlet</artifactId>
        <version>2.2.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tiles</groupId>
        <artifactId>tiles-template</artifactId>
        <version>2.2.1</version>
    </dependency>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号