Thanks. I didn't understand that both properties were needed. (And I
now understand what the configuration documentation was trying to tell me.)
This is now working for me, except for one thing:
The AOL converter seems to strip out all whitespace from the html it
generates. Since I'm not using the AOL converter here, (the velocity
templates are serving the function of providing the html), whitespace is
not getting stripped and the output ends up looking not so hot. The
whole point of doing this is to be able to code the templates more or
less visually as simple html pages. I don't want unreadable templates.
So I need an html whitespace stripper. I suppose I could use JTidy but
I'd like to avoid adding yet another jar. Is there anything in Velocity
itself (or perhaps in the Apache toolset) that takes html and strips out
the whitespace?
Nathan Bubna wrote:
yeah, the WebappLoader was renamed to the WebappResourceLoader for
VelocityTools 2
and your properties need to be:
resource.loader = webapp
webapp.resource.loader.class =
org.apache.velocity.tools.view.servlet.WebappLoader
the resource.loader property names the resource loaders you want to
use (in the order desired), then the other properties must be prefixed
with the proper names.
and yeah, singleton should work as well as the engine, though i
recommend using the engine unless you have a good reason for using the
singleton.
On Sun, Dec 28, 2008 at 5:23 PM, Steve Cohen <[email protected]> wrote:
Thanks, Nathan. This sounds like the right approach.
Do you mean org.apache.velocity.tools.view.servlet.WebappLoader?
I don't find a WebappResourceLoader. Assuming you do mean the WebappLoader,
then I'm having a little trouble getting it to initialize properly. Will
your method work with the Singleton approach?
My initialization code is as follows:
public static void initVelocity(ServletContext ctx)
throws VelocityInitializationException
{
Velocity.setProperty(
RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
"org.apache.velocity.runtime.log.Log4JLogChute" );
Velocity.setProperty("runtime.log.logsystem.log4j.logger",
"Velocity");
Velocity.setProperty("resource.loader.class",
"org.apache.velocity.tools.view.servlet.WebappLoader");
Velocity.setApplicationAttribute("javax.servlet.ServletContext",
ctx);
try {
Velocity.init();
} catch (Exception e) {
throw new VelocityInitializationException(e);
}
}
Yet when I run it I see the following in the log:
2008-12-28 19:12:08,166 [main] DEBUG Velocity - ResourceLoader
instantiated: org.apache.velocity.runtime.resource.loader.FileResourceLoader
and when I go to access my templates they, of course, can't be found.
What am I doing wrong?
Steve
Nathan Bubna wrote:
...
Yeah, i don't think you really need the VelocityViewServlet. (Note
that the VelocityServlet class is deprecated). But so long as you
are running in a webapp container like Tomcat and have access to a
ServletContext, you can use the WebappResourceLoader (from
VelocityTools 2) to load templates from your web context. Just
remember to put the ServletContext object in your VelocityEngine (or
singleton) application attributes before you initialize it:
VelocityEngine engine = new VelocityEngine();
engine.setApplicationAttribute("javax.servlet.ServletContext",
theServletContext);
engine.init(properties);
...
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]