You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by carlo latasa <cl...@gmail.com> on 2008/12/04 18:19:33 UTC

VelocityEngine...

So in the webwork 1.x code I have, there's a subclass of the velocity
runtime Directive class that has some code like the following:

    protected VelocityEngine velocityEngine =
VelocityManager.getInstance().getVelocityEngine();
    Template template = velocityEngine.getTemplate(templateName);

Re: VelocityEngine...

Posted by Nathan Bubna <nb...@gmail.com>.
On Thu, Dec 4, 2008 at 2:27 PM, carlo latasa <cl...@gmail.com> wrote:
> Ok - re-read the Velocity docs and am finding that I have to use absolute
> paths for file.resource.loader.path in the velocity.properties. If the path
> is just "." or "WEB-INF" is it relative to the jar location or ?

if the path is not absolute, it is relative to the directory the JVM
was started up in.  this is obviously not very web-application
friendly.

for a web application, it is strongly recommended that you use the
ClasspathResourceLoader or the WebappResourceLoader, the latter being
part of VelocityTools and probably your best choice.  Just add the
VelocityTools 2.0-beta3 jar to your lib and change your properties to:

resource.loader = webapp
webapp.resource.loader.class =
org.apache.velocity.tools.view.WebappResourceLoader
webapp.resource.loader.path = /WEB-INF/

> Either way, I'm still getting ResourceNotFoundException  when trying to find
> my vm (when I know its there and it's permissions allow for reading). Could
> it be an encoding issue?
>
> Here's what my velocity.log sayz:
>
> 2008-12-04 14:16:03,795 - Trying to use logger class
> org.apache.velocity.runtime.log.Log4JLogChute
> 2008-12-04 14:16:03,795 - Using logger class
> org.apache.velocity.runtime.log.Log4JLogChute
> 2008-12-04 14:16:03,795 - Default ResourceManager initializing. (class
> org.apache.velocity.runtime.resource.ResourceManagerImpl)
> 2008-12-04 14:16:03,796 - ResourceLoader instantiated:
> org.apache.velocity.runtime.resource.loader.FileResourceLoader
> 2008-12-04 14:16:03,796 - FileResourceLoader : initialization starting.
> 2008-12-04 14:16:03,796 - Do unicode file recognition:  false
> 2008-12-04 14:16:03,796 - FileResourceLoader : adding path
> '/Users/carlo/ccs/denali/webapp'
> 2008-12-04 14:16:03,796 - FileResourceLoader : initialization complete.
> 2008-12-04 14:16:03,796 - ResourceCache: initialized (class
> org.apache.velocity.runtime.resource.ResourceCacheImpl)
> 2008-12-04 14:16:03,797 - Default ResourceManager initialization complete.
> 2008-12-04 14:16:03,797 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Literal
> 2008-12-04 14:16:03,797 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Macro
> 2008-12-04 14:16:03,798 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Parse
> 2008-12-04 14:16:03,798 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Include
> 2008-12-04 14:16:03,798 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Foreach
> 2008-12-04 14:16:03,807 - Created '20' parsers.
> 2008-12-04 14:16:03,808 - Velocimacro : initialization starting.
> 2008-12-04 14:16:03,809 - Velocimacro : "velocimacro.library" is not set.
> Trying default library: VM_global_library.vm
> 2008-12-04 14:16:03,817 - Velocimacro : Default library not found.
> 2008-12-04 14:16:03,818 - Velocimacro : allowInline = true : VMs can be
> defined inline in templates
> 2008-12-04 14:16:03,818 - Velocimacro : allowInlineToOverride = false : VMs
> defined inline may NOT replace previous VM definitions
> 2008-12-04 14:16:03,818 - Velocimacro : allowInlineLocal = false : VMs
> defined inline will be global in scope if allowed.
> 2008-12-04 14:16:03,818 - Velocimacro : autoload off : VM system will not
> automatically reload global library macros
> 2008-12-04 14:16:03,818 - Velocimacro : Velocimacro : initialization
> complete.
> 2008-12-04 14:16:03,818 - RuntimeInstance successfully initialized.
> 2008-12-04 14:16:32,477 - ResourceManager : unable to find resource
> '/Users/carlo/ccs/denali/webapp/template/dashheader.vm' in any resource
> loader.
>
> Ouch.
>
> On Thu, Dec 4, 2008 at 12:20 PM, carlo latasa <cl...@gmail.com> wrote:
>
>> Thanks both of you for the quick response.
>>
>> So I'm now creating a static instance of the VelocityEngine in my Directive
>> base class and calling init in a static initalizer.
>>
>> Now when getTemplate is called on the velocityEngine instance I get:
>>
>> org.apache.velocity.exception.ResourceNotFoundException: Unable to find
>> resource '/templates/dashheader.vm'
>>     at
>> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
>>     at
>> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
>>     at
>> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)...
>>
>> There's a setting in either velocity.properties or struts.properties that
>> tells the engine where to look. What is that setting?
>>
>> I'm assuming that calling init() on the engine with no params will default
>> to using the velocity.properties file in my WEB-INF/classes dir.
>>
>> Thanks again.
>>
>>
>>
>
>
> --
> Carlo Latasa
> EdgeDriven.com
> Cell: (415) 385-1567
>

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


Re: VelocityEngine...

Posted by carlo latasa <cl...@gmail.com>.
So a solution that ended up working is getting the VelocityEngine from the
VelocityViewServlet. I extended the VelocityViewServlet, overrode the init
method and pulled the VelocityEngine from it. Only that VelocityEngine
appears to be capable of loading .vm Templates that are within my WEB-INF
directory.

I would have hoped that I could have also just used the Velocity.getTemplate
singleton but apparently when your running an application server (Tomcat in
this case), you have to use webapp as the resource.loader and if you want
THE real VelocityEngine you must ask the VelocityViewServlet. ? maybe ?

I get the feeling that the configuration and protocol for Velocity in a
web-application situation is slightly different from that described in the
developer-guide.

Thoughts?

On Thu, Dec 4, 2008 at 4:39 PM, carlo latasa <cl...@gmail.com> wrote:

> So now I've followed your recommendations about using the latest tools jar
> as well as replacing the file resource loader with the webapp one in my
> velocity.properties.
>
> The problem is that Velocity is able to load .vm's from my struts.xml file
> mappings just fine. It's in my custom template loading code where it throws
> the ResourceNotFoundException. Keep in mind that I want to just use the
> exact same properties as I have called out in my velocity.properties file.
>
> Here's that code:
>
>         Velocity.init(); // Tried referencing an absolute reference to my
> velocity.properties file and that makes no difference.
>
>
>  System.out.println(Velocity.getProperty("file.resource.loader.path")); //
> Allways prints out "." as opposed to "/WEB-INF/" ->
>
> // which is set in my velocity.properties with webapp.resource.loader.path.
>
>         Template template = Velocity.getTemplate( templateName); // Throws
> ResourceNotFoundException
>
> Note that I've tried making the templateName absolute, relative, just the
> filename.... Makes no difference.
>
> Here's a question, how do I get the exact same VelocityEngine that was
> successfully looking up the stuff in my struts.xml mappings? I saw other
> posts that said to use VelocityViewServlet - getVelocityEngine() but that
> always returned null. Moreover the tools 2.0 docs seem to indicate that that
> method is old school.  Seems like if internally Velocity has a singleton of
> the engine somewhere that it's using to find all of the other references in
> my web.xml, I could just get a hold of that one and use it...
>
> I'll keep reading the new docs for more clues.
>
>
>
>
> On Thu, Dec 4, 2008 at 2:27 PM, carlo latasa <cl...@gmail.com> wrote:
>
>> Ok - re-read the Velocity docs and am finding that I have to use absolute
>> paths for file.resource.loader.path in the velocity.properties. If the path
>> is just "." or "WEB-INF" is it relative to the jar location or ?
>>
>> Either way, I'm still getting ResourceNotFoundException  when trying to
>> find my vm (when I know its there and it's permissions allow for reading).
>> Could it be an encoding issue?
>>
>> Here's what my velocity.log sayz:
>>
>> 2008-12-04 14:16:03,795 - Trying to use logger class
>> org.apache.velocity.runtime.log.Log4JLogChute
>> 2008-12-04 14:16:03,795 - Using logger class
>> org.apache.velocity.runtime.log.Log4JLogChute
>> 2008-12-04 14:16:03,795 - Default ResourceManager initializing. (class
>> org.apache.velocity.runtime.resource.ResourceManagerImpl)
>> 2008-12-04 14:16:03,796 - ResourceLoader instantiated:
>> org.apache.velocity.runtime.resource.loader.FileResourceLoader
>> 2008-12-04 14:16:03,796 - FileResourceLoader : initialization starting.
>> 2008-12-04 14:16:03,796 - Do unicode file recognition:  false
>> 2008-12-04 14:16:03,796 - FileResourceLoader : adding path
>> '/Users/carlo/ccs/denali/webapp'
>> 2008-12-04 14:16:03,796 - FileResourceLoader : initialization complete.
>> 2008-12-04 14:16:03,796 - ResourceCache: initialized (class
>> org.apache.velocity.runtime.resource.ResourceCacheImpl)
>> 2008-12-04 14:16:03,797 - Default ResourceManager initialization complete.
>> 2008-12-04 14:16:03,797 - Loaded System Directive:
>> org.apache.velocity.runtime.directive.Literal
>> 2008-12-04 14:16:03,797 - Loaded System Directive:
>> org.apache.velocity.runtime.directive.Macro
>> 2008-12-04 14:16:03,798 - Loaded System Directive:
>> org.apache.velocity.runtime.directive.Parse
>> 2008-12-04 14:16:03,798 - Loaded System Directive:
>> org.apache.velocity.runtime.directive.Include
>> 2008-12-04 14:16:03,798 - Loaded System Directive:
>> org.apache.velocity.runtime.directive.Foreach
>> 2008-12-04 14:16:03,807 - Created '20' parsers.
>> 2008-12-04 14:16:03,808 - Velocimacro : initialization starting.
>> 2008-12-04 14:16:03,809 - Velocimacro : "velocimacro.library" is not set.
>> Trying default library: VM_global_library.vm
>> 2008-12-04 14:16:03,817 - Velocimacro : Default library not found.
>> 2008-12-04 14:16:03,818 - Velocimacro : allowInline = true : VMs can be
>> defined inline in templates
>> 2008-12-04 14:16:03,818 - Velocimacro : allowInlineToOverride = false :
>> VMs defined inline may NOT replace previous VM definitions
>> 2008-12-04 14:16:03,818 - Velocimacro : allowInlineLocal = false : VMs
>> defined inline will be global in scope if allowed.
>> 2008-12-04 14:16:03,818 - Velocimacro : autoload off : VM system will not
>> automatically reload global library macros
>> 2008-12-04 14:16:03,818 - Velocimacro : Velocimacro : initialization
>> complete.
>> 2008-12-04 14:16:03,818 - RuntimeInstance successfully initialized.
>> 2008-12-04 14:16:32,477 - ResourceManager : unable to find resource
>> '/Users/carlo/ccs/denali/webapp/template/dashheader.vm' in any resource
>> loader.
>>
>> Ouch.
>>
>>
>> On Thu, Dec 4, 2008 at 12:20 PM, carlo latasa <cl...@gmail.com> wrote:
>>
>>> Thanks both of you for the quick response.
>>>
>>> So I'm now creating a static instance of the VelocityEngine in my
>>> Directive base class and calling init in a static initalizer.
>>>
>>> Now when getTemplate is called on the velocityEngine instance I get:
>>>
>>> org.apache.velocity.exception.ResourceNotFoundException: Unable to find
>>> resource '/templates/dashheader.vm'
>>>     at
>>> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
>>>     at
>>> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
>>>     at
>>> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)...
>>>
>>> There's a setting in either velocity.properties or struts.properties that
>>> tells the engine where to look. What is that setting?
>>>
>>> I'm assuming that calling init() on the engine with no params will
>>> default to using the velocity.properties file in my WEB-INF/classes dir.
>>>
>>> Thanks again.
>>>
>>>
>>>
>>
>>
>> --
>> Carlo Latasa
>> EdgeDriven.com
>> Cell: (415) 385-1567
>>
>
>
>
> --
> Carlo Latasa
> EdgeDriven.com
> Cell: (415) 385-1567
>



-- 
Carlo Latasa
EdgeDriven.com
Cell: (415) 385-1567

Re: VelocityEngine...

Posted by carlo latasa <cl...@gmail.com>.
So now I've followed your recommendations about using the latest tools jar
as well as replacing the file resource loader with the webapp one in my
velocity.properties.

The problem is that Velocity is able to load .vm's from my struts.xml file
mappings just fine. It's in my custom template loading code where it throws
the ResourceNotFoundException. Keep in mind that I want to just use the
exact same properties as I have called out in my velocity.properties file.

Here's that code:

        Velocity.init(); // Tried referencing an absolute reference to my
velocity.properties file and that makes no difference.


 System.out.println(Velocity.getProperty("file.resource.loader.path")); //
Allways prints out "." as opposed to "/WEB-INF/" ->

// which is set in my velocity.properties with webapp.resource.loader.path.

        Template template = Velocity.getTemplate( templateName); // Throws
ResourceNotFoundException

Note that I've tried making the templateName absolute, relative, just the
filename.... Makes no difference.

Here's a question, how do I get the exact same VelocityEngine that was
successfully looking up the stuff in my struts.xml mappings? I saw other
posts that said to use VelocityViewServlet - getVelocityEngine() but that
always returned null. Moreover the tools 2.0 docs seem to indicate that that
method is old school.  Seems like if internally Velocity has a singleton of
the engine somewhere that it's using to find all of the other references in
my web.xml, I could just get a hold of that one and use it...

I'll keep reading the new docs for more clues.



On Thu, Dec 4, 2008 at 2:27 PM, carlo latasa <cl...@gmail.com> wrote:

> Ok - re-read the Velocity docs and am finding that I have to use absolute
> paths for file.resource.loader.path in the velocity.properties. If the path
> is just "." or "WEB-INF" is it relative to the jar location or ?
>
> Either way, I'm still getting ResourceNotFoundException  when trying to
> find my vm (when I know its there and it's permissions allow for reading).
> Could it be an encoding issue?
>
> Here's what my velocity.log sayz:
>
> 2008-12-04 14:16:03,795 - Trying to use logger class
> org.apache.velocity.runtime.log.Log4JLogChute
> 2008-12-04 14:16:03,795 - Using logger class
> org.apache.velocity.runtime.log.Log4JLogChute
> 2008-12-04 14:16:03,795 - Default ResourceManager initializing. (class
> org.apache.velocity.runtime.resource.ResourceManagerImpl)
> 2008-12-04 14:16:03,796 - ResourceLoader instantiated:
> org.apache.velocity.runtime.resource.loader.FileResourceLoader
> 2008-12-04 14:16:03,796 - FileResourceLoader : initialization starting.
> 2008-12-04 14:16:03,796 - Do unicode file recognition:  false
> 2008-12-04 14:16:03,796 - FileResourceLoader : adding path
> '/Users/carlo/ccs/denali/webapp'
> 2008-12-04 14:16:03,796 - FileResourceLoader : initialization complete.
> 2008-12-04 14:16:03,796 - ResourceCache: initialized (class
> org.apache.velocity.runtime.resource.ResourceCacheImpl)
> 2008-12-04 14:16:03,797 - Default ResourceManager initialization complete.
> 2008-12-04 14:16:03,797 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Literal
> 2008-12-04 14:16:03,797 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Macro
> 2008-12-04 14:16:03,798 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Parse
> 2008-12-04 14:16:03,798 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Include
> 2008-12-04 14:16:03,798 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Foreach
> 2008-12-04 14:16:03,807 - Created '20' parsers.
> 2008-12-04 14:16:03,808 - Velocimacro : initialization starting.
> 2008-12-04 14:16:03,809 - Velocimacro : "velocimacro.library" is not set.
> Trying default library: VM_global_library.vm
> 2008-12-04 14:16:03,817 - Velocimacro : Default library not found.
> 2008-12-04 14:16:03,818 - Velocimacro : allowInline = true : VMs can be
> defined inline in templates
> 2008-12-04 14:16:03,818 - Velocimacro : allowInlineToOverride = false : VMs
> defined inline may NOT replace previous VM definitions
> 2008-12-04 14:16:03,818 - Velocimacro : allowInlineLocal = false : VMs
> defined inline will be global in scope if allowed.
> 2008-12-04 14:16:03,818 - Velocimacro : autoload off : VM system will not
> automatically reload global library macros
> 2008-12-04 14:16:03,818 - Velocimacro : Velocimacro : initialization
> complete.
> 2008-12-04 14:16:03,818 - RuntimeInstance successfully initialized.
> 2008-12-04 14:16:32,477 - ResourceManager : unable to find resource
> '/Users/carlo/ccs/denali/webapp/template/dashheader.vm' in any resource
> loader.
>
> Ouch.
>
>
> On Thu, Dec 4, 2008 at 12:20 PM, carlo latasa <cl...@gmail.com> wrote:
>
>> Thanks both of you for the quick response.
>>
>> So I'm now creating a static instance of the VelocityEngine in my
>> Directive base class and calling init in a static initalizer.
>>
>> Now when getTemplate is called on the velocityEngine instance I get:
>>
>> org.apache.velocity.exception.ResourceNotFoundException: Unable to find
>> resource '/templates/dashheader.vm'
>>     at
>> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
>>     at
>> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
>>     at
>> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)...
>>
>> There's a setting in either velocity.properties or struts.properties that
>> tells the engine where to look. What is that setting?
>>
>> I'm assuming that calling init() on the engine with no params will default
>> to using the velocity.properties file in my WEB-INF/classes dir.
>>
>> Thanks again.
>>
>>
>>
>
>
> --
> Carlo Latasa
> EdgeDriven.com
> Cell: (415) 385-1567
>



-- 
Carlo Latasa
EdgeDriven.com
Cell: (415) 385-1567

Re: VelocityEngine...

Posted by carlo latasa <cl...@gmail.com>.
Ok - re-read the Velocity docs and am finding that I have to use absolute
paths for file.resource.loader.path in the velocity.properties. If the path
is just "." or "WEB-INF" is it relative to the jar location or ?

Either way, I'm still getting ResourceNotFoundException  when trying to find
my vm (when I know its there and it's permissions allow for reading). Could
it be an encoding issue?

Here's what my velocity.log sayz:

2008-12-04 14:16:03,795 - Trying to use logger class
org.apache.velocity.runtime.log.Log4JLogChute
2008-12-04 14:16:03,795 - Using logger class
org.apache.velocity.runtime.log.Log4JLogChute
2008-12-04 14:16:03,795 - Default ResourceManager initializing. (class
org.apache.velocity.runtime.resource.ResourceManagerImpl)
2008-12-04 14:16:03,796 - ResourceLoader instantiated:
org.apache.velocity.runtime.resource.loader.FileResourceLoader
2008-12-04 14:16:03,796 - FileResourceLoader : initialization starting.
2008-12-04 14:16:03,796 - Do unicode file recognition:  false
2008-12-04 14:16:03,796 - FileResourceLoader : adding path
'/Users/carlo/ccs/denali/webapp'
2008-12-04 14:16:03,796 - FileResourceLoader : initialization complete.
2008-12-04 14:16:03,796 - ResourceCache: initialized (class
org.apache.velocity.runtime.resource.ResourceCacheImpl)
2008-12-04 14:16:03,797 - Default ResourceManager initialization complete.
2008-12-04 14:16:03,797 - Loaded System Directive:
org.apache.velocity.runtime.directive.Literal
2008-12-04 14:16:03,797 - Loaded System Directive:
org.apache.velocity.runtime.directive.Macro
2008-12-04 14:16:03,798 - Loaded System Directive:
org.apache.velocity.runtime.directive.Parse
2008-12-04 14:16:03,798 - Loaded System Directive:
org.apache.velocity.runtime.directive.Include
2008-12-04 14:16:03,798 - Loaded System Directive:
org.apache.velocity.runtime.directive.Foreach
2008-12-04 14:16:03,807 - Created '20' parsers.
2008-12-04 14:16:03,808 - Velocimacro : initialization starting.
2008-12-04 14:16:03,809 - Velocimacro : "velocimacro.library" is not set.
Trying default library: VM_global_library.vm
2008-12-04 14:16:03,817 - Velocimacro : Default library not found.
2008-12-04 14:16:03,818 - Velocimacro : allowInline = true : VMs can be
defined inline in templates
2008-12-04 14:16:03,818 - Velocimacro : allowInlineToOverride = false : VMs
defined inline may NOT replace previous VM definitions
2008-12-04 14:16:03,818 - Velocimacro : allowInlineLocal = false : VMs
defined inline will be global in scope if allowed.
2008-12-04 14:16:03,818 - Velocimacro : autoload off : VM system will not
automatically reload global library macros
2008-12-04 14:16:03,818 - Velocimacro : Velocimacro : initialization
complete.
2008-12-04 14:16:03,818 - RuntimeInstance successfully initialized.
2008-12-04 14:16:32,477 - ResourceManager : unable to find resource
'/Users/carlo/ccs/denali/webapp/template/dashheader.vm' in any resource
loader.

Ouch.

On Thu, Dec 4, 2008 at 12:20 PM, carlo latasa <cl...@gmail.com> wrote:

> Thanks both of you for the quick response.
>
> So I'm now creating a static instance of the VelocityEngine in my Directive
> base class and calling init in a static initalizer.
>
> Now when getTemplate is called on the velocityEngine instance I get:
>
> org.apache.velocity.exception.ResourceNotFoundException: Unable to find
> resource '/templates/dashheader.vm'
>     at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
>     at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
>     at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)...
>
> There's a setting in either velocity.properties or struts.properties that
> tells the engine where to look. What is that setting?
>
> I'm assuming that calling init() on the engine with no params will default
> to using the velocity.properties file in my WEB-INF/classes dir.
>
> Thanks again.
>
>
>


-- 
Carlo Latasa
EdgeDriven.com
Cell: (415) 385-1567

Re: VelocityEngine...

Posted by carlo latasa <cl...@gmail.com>.
Thanks both of you for the quick response.

So I'm now creating a static instance of the VelocityEngine in my Directive
base class and calling init in a static initalizer.

Now when getTemplate is called on the velocityEngine instance I get:

org.apache.velocity.exception.ResourceNotFoundException: Unable to find
resource '/templates/dashheader.vm'
    at
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
    at
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
    at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)...

There's a setting in either velocity.properties or struts.properties that
tells the engine where to look. What is that setting?

I'm assuming that calling init() on the engine with no params will default
to using the velocity.properties file in my WEB-INF/classes dir.

Thanks again.

Re: VelocityEngine...

Posted by Nathan Bubna <nb...@gmail.com>.
You've read the Developer Guide, right? :)

http://velocity.apache.org/engine/releases/velocity-1.6/developer-guide.html

On Thu, Dec 4, 2008 at 11:44 AM, carlo latasa <cl...@gmail.com> wrote:
> Thanks both of you for the quick response.
>
> So I'm not creating a static instance of the VelocityEngine in my Directive
> base class and calling init in a static initalizer.
>
> Now when getTemplate is called on the velocityEngine instance I get:
>
> org.apache.velocity.exception.ResourceNotFoundException: Unable to find
> resource '/templates/dashheader.vm'
>    at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
>    at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
>    at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)...
>
> There's a setting in either velocity.properties or struts.properties that
> tells the engine where to look. What is that setting?
>
> I'm assuming that calling init() on the engine with no params will default
> to using the velocity.properties file in my WEB-INF/classes dir.
>
> Thanks again.
>
> On Thu, Dec 4, 2008 at 9:19 AM, carlo latasa <cl...@gmail.com> wrote:
>
>> So in the webwork 1.x code I have, there's a subclass of the velocity
>> runtime Directive class that has some code like the following:
>>
>>     protected VelocityEngine velocityEngine =
>> VelocityManager.getInstance().getVelocityEngine();
>>     Template template = velocityEngine.getTemplate(templateName);
>>
>>
>>
>
>
> --
> Carlo Latasa
> EdgeDriven.com
> Cell: (415) 385-1567
>

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


Re: VelocityEngine...

Posted by carlo latasa <cl...@gmail.com>.
Thanks both of you for the quick response.

So I'm not creating a static instance of the VelocityEngine in my Directive
base class and calling init in a static initalizer.

Now when getTemplate is called on the velocityEngine instance I get:

org.apache.velocity.exception.ResourceNotFoundException: Unable to find
resource '/templates/dashheader.vm'
    at
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
    at
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
    at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)...

There's a setting in either velocity.properties or struts.properties that
tells the engine where to look. What is that setting?

I'm assuming that calling init() on the engine with no params will default
to using the velocity.properties file in my WEB-INF/classes dir.

Thanks again.

On Thu, Dec 4, 2008 at 9:19 AM, carlo latasa <cl...@gmail.com> wrote:

> So in the webwork 1.x code I have, there's a subclass of the velocity
> runtime Directive class that has some code like the following:
>
>     protected VelocityEngine velocityEngine =
> VelocityManager.getInstance().getVelocityEngine();
>     Template template = velocityEngine.getTemplate(templateName);
>
>
>


-- 
Carlo Latasa
EdgeDriven.com
Cell: (415) 385-1567

Re: VelocityEngine...

Posted by Claude Brisson <cl...@renegat.net>.
I guess Carlo is trying to obtain an instance of Velocity...

Carlo, you can use the static class org.apache.velocity.app.Velocity
(singleton model), or instanciate an instance of
org.apache.velocity.app.VelocityEngine.

In both cases, it must be initialized via oneof the init() methods.


  Claude

On jeu, 2008-12-04 at 09:44 -0800, Nathan Bubna wrote:
> The VelocityManager class is a part of WebWork, not Velocity.  So, i
> don't see how the Velocity version is relevant here...
> 
> On Thu, Dec 4, 2008 at 9:21 AM, carlo latasa <cl...@gmail.com> wrote:
> > On Thu, Dec 4, 2008 at 9:19 AM, carlo latasa <cl...@gmail.com> wrote:
> >
> >> So in the webwork 1.x code I have, there's a subclass of the velocity
> >> runtime Directive class that has some code like the following:
> >>
> >>     VelocityEngine velocityEngine =
> >> VelocityManager.getInstance().getVelocityEngine();
> >>     Template template = velocityEngine.getTemplate(templateName);
> >
> >
> > however it looks like you can no longer get the velocityengine from the
> > velocitymanager. How would I do this now using Velocity 1.5?
> >
> > (Sorry for the last partial post)
> >
> > Carlo.
> >
> 
> ---------------------------------------------------------------------
> 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


Re: VelocityEngine...

Posted by Nathan Bubna <nb...@gmail.com>.
The VelocityManager class is a part of WebWork, not Velocity.  So, i
don't see how the Velocity version is relevant here...

On Thu, Dec 4, 2008 at 9:21 AM, carlo latasa <cl...@gmail.com> wrote:
> On Thu, Dec 4, 2008 at 9:19 AM, carlo latasa <cl...@gmail.com> wrote:
>
>> So in the webwork 1.x code I have, there's a subclass of the velocity
>> runtime Directive class that has some code like the following:
>>
>>     VelocityEngine velocityEngine =
>> VelocityManager.getInstance().getVelocityEngine();
>>     Template template = velocityEngine.getTemplate(templateName);
>
>
> however it looks like you can no longer get the velocityengine from the
> velocitymanager. How would I do this now using Velocity 1.5?
>
> (Sorry for the last partial post)
>
> Carlo.
>

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


Re: VelocityEngine...

Posted by carlo latasa <cl...@gmail.com>.
On Thu, Dec 4, 2008 at 9:19 AM, carlo latasa <cl...@gmail.com> wrote:

> So in the webwork 1.x code I have, there's a subclass of the velocity
> runtime Directive class that has some code like the following:
>
>     VelocityEngine velocityEngine =
> VelocityManager.getInstance().getVelocityEngine();
>     Template template = velocityEngine.getTemplate(templateName);


however it looks like you can no longer get the velocityengine from the
velocitymanager. How would I do this now using Velocity 1.5?

(Sorry for the last partial post)

Carlo.