Announcement Announcement Module
Collapse
No announcement yet.
Struts/Velocity setup confusion Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Struts/Velocity setup confusion

    I am new to spring so I am not quite sure how all the pieces fit so here is my problem:

    I am writing struts app and I need to be able to use Velocity for views.


    my spring config file:

    <bean id="velocityEngine" singleton="true" class="org.springframework.ui.velocity.VelocityEng ineFactoryBean">
    <property name="velocityPropertiesMap">
    <map>
    <entry key="resource.loader">
    <value>ds, class</value>
    </entry>

    <entry key="class.resource.loader.class">
    <value>org.apache.velocity.runtime.resource.loader .ClasspathResourceLoader</value>
    </entry>

    <entry key="ds.resource.loader.instance">
    <ref bean="templateLoader"/>
    </entry>
    <entry key="ds.resource.loader.resource.table">
    <value>velocity_template</value>
    </entry>
    <entry key="ds.resource.loader.resource.keycolumn">
    <value>name</value>
    </entry>
    <entry key="ds.resource.loader.resource.templatecolumn">
    <value>content</value>
    </entry>
    <entry key="ds.resource.loader.resource.timestampcolumn">
    <value>update_tstamp</value>
    </entry>
    </map>
    </property>
    </bean>

    <bean id="templateLoader" singleton="true" class="org.apache.velocity.runtime.resource.loader .DataSourceResourceLoader">
    <property name="dataSource">
    <ref local="dataSource"/>
    </property>
    </bean>

    <bean id="velocityConfigurer" class="org.springframework.web.servlet.view.veloci ty.VelocityConfigurer">
    <property name="velocityEngine">
    <ref local="velocityEngine" />
    </property>
    </bean>

    Now...should I use VelocityViewServlet(i'll have to configure everything again) or can I use VelocityViewResolver?

    <bean id="viewResolver" class="org.springframework.web.servlet.view.veloci ty.VelocityViewResolver">
    <property name="suffix">
    <value>.vm</value>
    </property>
    <property name="toolboxConfigLocation">
    <value>/WEB-INF/toolbox.xml</value>
    </property>
    <property name="exposeRequestAttributes">
    <value>true</value>
    </property>
    </bean>

    If I use VelocityViewResolver what additional components do I need to configure?

  • #2
    Basically, Struts forward to a view processor. That is, if you want to use Velocity, you should configure VelocityViewServlet in your web.xml
    For more information on using/configuring Struts with Spring, please review Chapter 15. Integrating with other web frameworks.

    Hope this helps.

    Comment


    • #3
      I got struts to play nice with spring - my problem is velocity. I already have Velocity Engine configured in spring and I would like to reuse that configuration (see my configs above). If I configure VelocityVewServlet in web.xml I will have to configure another Velocity engine.

      Comment

      Working...
      X