velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Burton" <>
Subject Re: ContextTool
Date Tue, 05 Mar 2002 06:00:49 GMT

Sounds like what you're looking for is some kind of "pull" tool.  The
Turbine framework supports this methodology which you can read about at  You could
also roll your own pull tool to do something similar.  Create a class with
a "get" method that takes the name of the class (or an alias) that you
want to load.  When the get method in your tool class is called, it would
instantiate the desired class if that had not already been done for the
request and then return the reference to it.   Assuming the tool helper
class was put into the context as "tool", you'd access your class like:

You could associate the name "myclass" to be used as the context name with
the class name in or by other similar means.

The WebWork framework ( supports
a similar but Model-1 type approach.  The #bean macro can be used to
instantiate any class with a public null contstructor. Or, the #action
macro will instantiate a class that implements the WebWork Action
interface.  In both cases, you may need to call the #execute macro to
execute some logic.  WebWork isn't quite released as 1.0, so if you're
interested it would be best to pull it from CVS.

Struts, Turbine, WebWork and other frameworks all support the Model-2
(MVC) approach where requests are directed to a controller servlet that
delegates to some Action class to execute some business logic.  From there
the request is usually forwarded to the template.  However, these Action
type classes tend to be used for business logic as opposed to simple
helper functions.  


Shawn Church wrote:
> That's essentially what I'm looking for, as long as the tool is instantiated
> only on its first use.  I have read over the Velocity developer's guide, but
> I may not have noticed the implementation.  So far, I have been explicitly
> loading these tool classes into the context on each request.  However, not
> every page will necessarily make use of these tools, so the instantiation is
> wasted in these cases.
> -----Original Message-----
> From: Geir Magnusson Jr. []
> Sent: Monday, March 04, 2002 12:07 PM
> To:
> Subject: Re: ContextTool
> On 3/4/02 12:35 PM, "Shawn Church" <> wrote:
> > I have used WebMacro extensively over the past couple of years, but I am
> > also curious about Velocity.  It seems to work pretty much as expected,
> but
> > I haven't noticed an equivalent interface in Velocity to the WebMacro
> > ContextTool.  Does anything like this exist in Velocity?
> >
> Do you mean autoloading of tool classes in the context?
> --
> Geir Magnusson Jr.                           
> System and Software Consulting
> Age and treachery will always triumph over youth and talent
> --
> To unsubscribe, e-mail:
> <>
> For additional commands, e-mail:
> <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message