On 3/28/07, Dave, Tejas <[EMAIL PROTECTED]> wrote:
Hi All,
I followed your discussion here but I have a question? Once
velocity.properties file has webapp.resource.loader.path = /templates
variable how does the web.xml file know to read from the
velocity.properties.
If you are using the VelocityViewServlet from VelocityTools 1.3, you
need only place your velocity.properties file in the /WEB-INF
directory of your webapp. The VelocityViewServlet will automatically
check for the file at /WEB-INF/velocity.properties.
If you are using an earlier version of VelocityTools, then you need to
tell the VelocityViewServlet where to look by adding an init-param to
the servlet config in your web.xml with the name of
org.apache.velocity.properties with the value being the path from the
root of the webapp to your velocity.properties file. Examples of
this can be found in the example applications that come with the
VelocityTools 1.2 distributions.
Do we invoke/initalise velocity in any particular way?
Yes, look at the source code for VelocityViewServlet's
initVelocity(ServletConfig) method to see what needs to happen. It is
particularly important that the ServletContext be placed in the
VelocityEngine's application attributes (using
"javax.servlet.ServletContext" as the key) so the WebappLoader can
find it.
How does the WebappLoader finds the template and the template can
be read?
The WebappLoader appends the name of the requested template to the
configured search path(s) for the loader and requests the resulting
file path from servletContext.getResourceAsStream(path).
I have similar web-app setup and want to place template file in
templates directory under the web-inf folder of webapp. Currently I
also face the issue that template file cant be found. Please guide me.
are you using the VelocityViewServlet? if not, how are you
configuring your VelocityEngine (or the singleton, if that's what
you're using)? what are your velocity.properties?
Thanks,
Tejas
[EMAIL PROTECTED]
-----Original Message-----
From: Nathan Bubna [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 08, 2007 11:26 PM
To: Velocity Users List
Subject: Re: Velocity template file path
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/ve
locity/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/ve
locity/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]
---------------------------------------------------------------------
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]