You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Geir Magnusson Jr." <ge...@optonline.net> on 2001/12/03 23:04:39 UTC
Re: Question about giving all contexts access to a resource
(equivalent to WebMacro ContextTool)
On 12/3/01 4:16 PM, "Mike Bridge" <mi...@bridgecanada.com> wrote:
> In WebMacro, I used to use a ContextTool to give all contexts
> access to a shared resource. In the Velocity documentation, it says
> that "all facilities like 'context tool'... are purposely left out
> of Velocity". My question is: what is the recommended way to port
> this over to Velocity? For example, I would like to provide all
> contexts with access to some sort of singleton string-lookup object.
Yes, I wrote that, and I guess I am going to revise it, because it's
misleading, I suppose.
The idea behind it is that in Velocity, we think of auto- Context stuff to
be the domain of the web framework or application that is using Velocity.
We don't aspire to be anything but a lil' ol template engine. :)
However, we tried to make it so that the Context system was a flexible as
possible, so you could tailor it to your specific needs, and not have to
bend to some model we came up with.
Just to be clear, this isn't a veiled criticism of WebMacro in any way. WM
is a bit different in it's philosophy here, and that's neither right or
wrong.
In Velocity, you can do a few things to solve what I assume your problem is
:
1) use a wrapped context, where you have a threadsafe shared context that
all can use :
VelocityContext vc = new VelocityContext( sharedContext )
And then everything in the sharedContext will be transparently available,
with the bonus that no one can overwrite the reference - any .put() or
#set() will be stored in the outer context, masking the inner, but not
harming it.
2) Cook up your own 'ToolContext' that does the autoloading of tools and
such... A little more work, but if it s a model you use all the time, might
be easier in the long run.
Geir
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>