velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Bubna" <nbu...@gmail.com>
Subject Re: Which flavor of Velocity to use?
Date Mon, 29 Dec 2008 01:36:59 GMT
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 <scohen@javactivity.org> 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);
>> ...
>>
>>
>>>
>>> Thanks.
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>>> For additional commands, e-mail: user-help@velocity.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message