You subclass VelocityView like this:
package com.foo;
import org.apache.velocity.tools.view.*;
public class MyVelocityView extends VelocityView
protected void configure(final JeeConfig config, final
VelocityEngine velocity) {
super.configure(config, velocity);
//do your stuff here
}
}
so long as you put the context-param i said, your MyVelocityView class
will automatically be used. and no, VelocityEngine config has been
moved into the VelocityView class, so the two options i gave you are
pretty much it.
On Tue, Jun 22, 2010 at 1:06 PM, B. Scott Smith <[email protected]> wrote:
> Thanks for the reply.
> I'm not sure how I would subclass VelocityView, as my application is already
> subclassing VelocityViewServlet. I currently override init() which
> eventually calls super.init(), and I also override handleRequest().
>
> Do I have any choices in this case? Thanks again.
> - Scott
>
> On 6/22/2010 2:17 PM, Nathan Bubna wrote:
>>
>> Unfortunately, in the quest to simplify other things and improve
>> performance, this particular sort of customization is now a little
>> more complicated. There are two ways to do it:
>>
>> Subclass VelocityView with the following:
>>
>> protected void configure(final JeeConfig config, final VelocityEngine
>> velocity) {
>> super.configure(config, velocity);
>> //do your stuff here
>> }
>>
>> and tell your VelocityView[Servlet/Filter/Tag]s to use it via:
>>
>> <context-param>
>> <param-name>org.apache.velocity.tools.view.class</param-name>
>> <param-value>com.foo.MyVelocityView</param-value>
>> </context-param>
>>
>> or alternately, you can try subclassing your
>> VelocityView[Servlet/Filter/Tag](s) directly and creating your own
>> VelocityEngine during init and then calling
>> getVelocityView().setVelocityEngine(myEngine), but then, of course,
>> you will not be taking advantage of all the VelocityEngine
>> configuration done by VelocityView and friends. So i recommend the
>> former option.
>>
>> On Tue, Jun 22, 2010 at 9:22 AM, B. Scott Smith<[email protected]>
>> wrote:
>>
>>>
>>> Hi, I am trying to migrate to Velocity Tools 2.0. My application
>>> currently
>>> needs to set a Velocity Property to a value that is determined at
>>> run-time.
>>> For example, I would like to set a property to one of two possible
>>> values,
>>> based on the current setting of my application's debug value. Before, I
>>> did
>>> this by simply overwriting the loadConfiguration() method:
>>>
>>> protected Properties loadConfiguration( ServletConfig config )
>>> throws IOException, FileNotFoundException
>>> {
>>> Properties velocityProps = new Properties( );
>>> if ( localDir != null ) {
>>> velocityProps.setProperty(
>>> Velocity.FILE_RESOURCE_LOADER_PATH, localDir );
>>> }
>>> velocityProps.setProperty( Velocity.RUNTIME_LOG, localDir +
>>> "velocity.log" );
>>> velocityProps.setProperty(
>>> Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS, debugFlag ?
>>>
>>> "org.apache.velocity.runtime.log.SimpleLog4JLogSystem" :
>>>
>>> "org.apache.velocity.runtime.log.NullLogSystem" );
>>> return velocityProps;
>>> }
>>>
>>>
>>> How can I accomplish the same thing in Tools 2.0?
>>> Thanks in advance for your help.
>>> - Scott Smith
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> 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]