Hi, 
I have somewhat of a related question.  

I would like to integrate VelocityViewServlet or VelocityStruts with my
current application.  My web application currently runs struts 1.2 as its
web framework.

I currently am using Velocity to generate XML files to be written to the
server and generate emails to be sent to users.  

My current configuration has Velocity running as a "general application".
With this style of configuration I need to specify an absolute path to my
templates rather than using a relative directory path from my Web Root
directory to locate my velocity templates (.vm).  I also call
Velocity.init() during application startup, to initialize the velocity
engine.

I feel that there may be another way of doing things.  Am I doing something
wrong in not leveraging the VelocityViewServlet, as some of the objects
written out will be stored in the  HttpServletRequest, HttpSession,
ServletContext, as well as other benefits such as GenericTools, etc.  

The reason I chose not to use VelocityViewServlet or VelocityStruts, is
because I am not using Velocity to create my presentation, rather I use
JSP's, JSTL, etc.  I use Velocity to solely generate the text/HTML email
string, and generate XML data files on my server.  The VelocityViewServlet
is tightly coupled with the HTTPResponse object, and I want to stay inside
struts for the most part.  That is why I chose to use Velocity as a general
application, which does work fine for my case.

However, everytime, I post from test to production, you can think of the
headaches that come with absolute path configuration and it doesn't take
advantage of tomcat deployment architecture.

So, is there a way I can utilize VelocityViewServlet and Velocity Struts
without having it so tightly binded to the presentation layer?  All I want
to do is specify relative paths for my velocity configurations and have the
ability to call Velocity.mergeTemplate().

Are these steps correct?
1) Add to Web.xml

        <servlet>  
                <servlet-name>velocity</servlet-name>
        
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</s
ervlet-class>
                <init-param>
                        <param-name>org.apache.velocity.toolbox</param-name>
                        <param-value>/WEB-INF/toolbox.xml</param-value>
                </init-param>
                <init-param>
        
<param-name>org.apache.velocity.properties</param-name>
        
<param-value>/WEB-INF/config/velocity.properties</param-value>
                </init-param>
                <load-on-startup>10</load-on-startup>
        </servlet>

        <servlet-mapping>
                <servlet-name>velocity</servlet-name>
                <url-pattern>*.vm</url-pattern>
        </servlet-mapping>
        
2) Make sure toolbox.xml and velocity.properties are in the proper
locations.  In velocity.properties relative paths from the Web Root
directory are valid.  That's just an assumption I have.

3) Start the application.

What I see is kind of weird.  What I had hoped to happen was that
Velocity.init(properties) would be called when my application launched.
This way hopefully I can use velocity throughout my app, and use relative
paths to my web root directory.  

It seems to me that the engine never started as I see no log file for
velocity.

What am I doing wrong?


Regards,
Edward Song

-----Original Message-----
From: Nathan Bubna [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 23, 2006 10:46 AM
To: Velocity Users List
Subject: Re: Web App and template .vm

Have you read:  http://jakarta.apache.org/velocity/webapps.html?

if you are using the VelocityViewServlet with its default properties, then
you just put the template files in the root directory of the webapp and it
will find them there.

On 1/22/06, Graham Renney <[EMAIL PROTECTED]> wrote:
> Hi
>
> I am struggling to get a web app to see the .vm template file unless I 
> place it in a physical location such as d:/template.vm and point the 
> velocity engine to that location. What I want to do is place it in my 
> war - but velocity does not find the template. Where do I place it in 
> the war and how do I tell the engine where it is?
>
> Thanks
> Graham Renney
>
>
> This message and any attachments are confidential and intended solely for
the addressee. If you have received this message in error, please notify
Discovery immediately, telephone number +27 11 529 2888. Any unauthorised
use; alteration or dissemination of the contents of this email is strictly
prohibited. In no event will Discovery or the sender be liable in any manner
whatsoever to any person for any loss or any direct, indirect, special or
consequential damages arising from use of this email or any linked website,
including, without limitation, from any lost profits, business interruption,
loss of programmes or other data that may be stored on any information
handling system or otherwise from any assurance that this email is virus
free even if Discovery is expressly advised of the possibility of such
damages. Discovery is an Authorised Financial Services Provider.
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to