You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by James Shaw <js...@zepler.net> on 2006/05/22 15:50:23 UTC

Using generic tools outside of webapp

I've seen some examples of using velocity generic tools in a webapp,
but none using them standalone.

I'm trying to use DateTool in a template.  While the docs say I can
use it "as you would any other POJO" I'm not sure how exactly.  AIUI,
I shouldn't require a toolbox.xml file as this is part of
VelocityView, is this right?  Some examples or documentation would be
appreciated ;-)

Thanks in advance
James Shaw

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


Re: Using generic tools outside of webapp

Posted by James Shaw <js...@zepler.net>.
On 22/05/06, Nathan Bubna <nb...@gmail.com> wrote:
> On 5/22/06, James Shaw <js...@zepler.net> wrote:
> > I've seen some examples of using velocity generic tools in a webapp,
> > but none using them standalone.
> >
> > I'm trying to use DateTool in a template.  While the docs say I can
> > use it "as you would any other POJO" I'm not sure how exactly.  AIUI,
> > I shouldn't require a toolbox.xml file as this is part of
> > VelocityView, is this right?
>
> correct, no toolbox is required for using generic tools.  you simple
> instantiate the tool, do any configuration you want manually, put it
> into the context, then use it in the template as you would anywhere
> else.
>
> > Some examples or documentation would be
> > appreciated ;-)
>
> here's a quick example:
>
> == java class that prepares your VelocityContext ===
> DateTool date = new DateTool();
> Whatever anyOtherPojo = new Whatever();
>
> context.put("date", date);
> =======================================

Many thanks, that's done the trick.

James Shaw

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


Re: Using generic tools outside of webapp

Posted by Nathan Bubna <nb...@gmail.com>.
On 5/22/06, James Shaw <js...@zepler.net> wrote:
> I've seen some examples of using velocity generic tools in a webapp,
> but none using them standalone.
>
> I'm trying to use DateTool in a template.  While the docs say I can
> use it "as you would any other POJO" I'm not sure how exactly.  AIUI,
> I shouldn't require a toolbox.xml file as this is part of
> VelocityView, is this right?

correct, no toolbox is required for using generic tools.  you simple
instantiate the tool, do any configuration you want manually, put it
into the context, then use it in the template as you would anywhere
else.

> Some examples or documentation would be
> appreciated ;-)

here's a quick example:

== java class that prepares your VelocityContext ===
DateTool date = new DateTool();
Whatever anyOtherPojo = new Whatever();

context.put("date", date);
=======================================

== template being processed ===
$date.short_time
$anyOtherPojo
=========================

Does that help?

> Thanks in advance
> James Shaw
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

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