简体   繁体   English

使用Velocity with Tiles和Spring

[英]Using Velocity with Tiles and Spring

I'm presently using Spring 3.0.4 and Apache Tiles 2.2.2 in my web app. 我目前在我的网络应用程序中使用Spring 3.0.4Apache Tiles 2.2.2 I'd like to replace JSP with Apache Velocity 1.6.3 but I'm somewhat confused on how to do this. 我想用Apache Velocity 1.6.3取代JSP,但我对如何做到这一点感到困惑。 Ultimately, I'd like to be able to do the following in a Tiles definition: 最后,我希望能够在Tiles定义中执行以下操作:

<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. 我目前正在使用标准的Spring VelocityConfigurer,TilesConfigurer,VelocityView,TilesView类。

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. 我已经创建了辅助类,其中包括与velocity集成的tile: https//github.com/pete911/openhouse-web当你向下滚动时有一个descritption。 classes can be found in maven central as well. 课程也可以在maven中心找到。

inside your servlet definition you need the following: 在servlet定义中,您需要以下内容:

    <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. 你可以看到你声明tiles.xml ..这是保存definiotion名称等的文件。

if you are using maven you need the following dependencies: 如果您使用maven,则需要以下依赖项:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM