You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Sebastian Gumpold <se...@sbs.co.at> on 2007/05/07 12:41:05 UTC
Static java classes
Hi all!
Is it possible to use static classes in a Velocity template?
When using
context.put("bla", instanceOfBla);
a concrete instance of a class is needed, so this of course doesn't work
for a static class.
Thanks a lot,
Sebastian
Re: Static java classes
Posted by Nathan Bubna <nb...@gmail.com>.
On 5/7/07, Sebastian Gumpold <se...@sbs.co.at> wrote:
> Hi all!
>
> Is it possible to use static classes in a Velocity template?
not without some really ugly, in-template reflection hacks.
> When using
> context.put("bla", instanceOfBla);
> a concrete instance of a class is needed, so this of course doesn't work
> for a static class.
yeah, an instance is needed for normal usage. adding support for
static utility classes has been discussed for a long time.
unfortunately, we didn't get it done for 1.5, but it is high on my
list of things-i'd-like-to-make-time-for so that we get it into 1.6.
if you're interested in helping, here's the discussion:
http://issues.apache.org/jira/browse/VELOCITY-102
> Thanks a lot,
> Sebastian
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: Static java classes
Posted by mailmur <ma...@yahoo.com>.
Once I had to publish ErrorCodes "constants" to
templates (ErrorCodes.INVALID_KEY etc...). Use
FieldMethodizer wrapper to publish constant fields.
ctx.put("ErrorCodes", new
FieldMethodizer(ErrorCodes));
And if you need access to static methods then can
always add a default constructor that does nothing.
ctx.put("Utils", new Utils());
If you dont want to add constructor to a pure static
class, FieldMethodizer may work for static methods as
well. I never tried it.
--- Sebastian Gumpold <se...@sbs.co.at>
wrote:
> Hi all!
>
> Is it possible to use static classes in a Velocity
> template?
>
> When using
> context.put("bla", instanceOfBla);
> a concrete instance of a class is needed, so this of
> course doesn't work
> for a static class.
>
> Thanks a lot,
> Sebastian
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org