velocity-user mailing list archives

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

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
http://jakarta.apache.org/turbine/turbine-2/pullmodel.html.  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:
    $tool.myclass...

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

The WebWork framework (http://sourceforge.net/projects/webwork/) 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.  

-Bill

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. [mailto:geirm@optonline.net]
> Sent: Monday, March 04, 2002 12:07 PM
> To: velocity-user@jakarta.apache.org
> Subject: Re: ContextTool
> 
> On 3/4/02 12:35 PM, "Shawn Church" <shawn@boxity.com> 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.                                     geirm@optonline.net
> System and Software Consulting
> 
> Age and treachery will always triumph over youth and talent
> 
> --
> To unsubscribe, e-mail:
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:velocity-user-help@jakarta.apache.org>

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


Mime
View raw message