you need to configure the singleton to use the WebappLoader as its
resource loader in your  velocity.properties and put the
ServletContext into the singleton's application attributes before
calling init(properties).  see:

http://svn.apache.org/viewvc/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/WebappLoader.java?view=markup

for why the ServletContext is needed, and the initVelocity(config) method of

http://svn.apache.org/viewvc/velocity/tools/trunk/src/java/org/apache/velocity/tools/view/servlet/VelocityViewServlet.java?revision=488468&view=markup

for an example of adding the ServletContext to the application attributes.

On 3/8/07, George, Nixon <[EMAIL PROTECTED]> wrote:
Thank you, that helped fix the problem. Can I use the same strategy of
webapploader in another webapp that uses the Singleton model (and not
VelocityViewServlet)? Igave it a shot but looks like just calling
Velocity.init() is not enough.

-----Original Message-----
From: Nathan Bubna [mailto:[EMAIL PROTECTED]
Sent: Wednesday, March 07, 2007 5:53 PM
To: Velocity Users List
Subject: Re: Velocity template file path

On 3/7/07, George, Nixon <[EMAIL PROTECTED]> wrote:
> I am using the VelocityViewServlet. I tried specifying the template
> folder as part of setting the default path in this code:
>
>         protected ExtendedProperties loadConfiguration(ServletConfig
> config)
>                                                         throws
> IOException {
>             ExtendedProperties p = new ExtendedProperties();
>
>         String path = config.getServletContext().getRealPath("/");
>         if (path == null){
>             path = "/";
>         }
>         p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,
> path+"\\templates\\");
>
>         return p;
>         }

no, the VelocityViewServlet doesn't use the FileResourceLoader, it
uses the WebappLoader.  you also don't need to override
loadConfiguration() method.  just create a velocity.properties file at
"/WEB-INF/velocity.properties" that contains the line:

webapp.resource.loader.path = /templates

(or something like that)

oh, and be sure that you are using VelocityTools 1.3, as the earlier
versions require you to tell the VelocityViewServlet where your
velocity.properties file is located explicitly.  the default location
is new to 1.3.

> But that didn't seem to work. If I put all the templates in the webapp
> root,  everything is dandy but it does not seem to like the way I am
> specifying the template path. Also, I had to put the double
backslashes
> because I am on a windows env.
>
> BTW, I searched for the WebappLoader tool but could not find it. Could
> you send me the URL? Thanks.

if you are using the VelocityViewServlet, it uses it by default.

javadoc is here:
http://velocity.apache.org/tools/releases/1.3/javadoc/org/apache/velocit
y/tools/view/servlet/WebappLoader.html


> -----Original Message-----
> From: Nathan Bubna [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 07, 2007 5:06 PM
> To: Velocity Users List
> Subject: Re: Velocity template file path
>
> - What servlet are you using?  The VelocityServlet (which is
> deprecated) or the VelocityViewServlet (which is part of VelocityTools
> and is the replacement for the VelocityServlet)?
>
> - Use of the FileResourceLoader in a webapp environment is not
> recommended.  The VelocityTools project comes with a WebappLoader that
> is much better for webapps.
>
> - If your templates are in /webapp/templates, then that is where you
> should point the resource loader; it would not be enough to point it
> at the webapp root and expect it to look for a "templates" folder
> automatically.
>
> - For examples of how to configure and use the VelocityViewServlet,
> you might consider checking out the example applications that come
> with VelocityTools.
>
>
> On 3/7/07, Nixon Sunny <[EMAIL PROTECTED]> wrote:
> > I am using the file resource loader to get the template. But, I am
> having
> > problems accessing it. Keeps getting error...
> >
> > org.apache.velocity.exception.ResourceNotFoundException: Unable to
> find
> > resource 'products.vm'
> >
> > My webapp structure is:
> >
> > webapp<root>
> > |
> > -- templates
> >
> > All my .vm files are inside the templates directory. I have
overridden
> the
> > loadConfiguration() method to make the webapp root as my default
file
> load
> > path. But, I guess thats not enough to point to the
/webapp/templates
> > directory. What am I missing?
> >
> > Thanks.
> >
> > _________________________________________________________________
> > With tax season right around the corner, make sure to follow these
few
> > simple tips.
> >
>
http://articles.moneycentral.msn.com/Taxes/PreparationTips/PreparationTi
> ps.aspx?icid=HMFebtagline
> >
> >
> >
---------------------------------------------------------------------
> > 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]
>
>
> ---------------------------------------------------------------------
> 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]


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