velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shinobu Kawai <>
Subject Re: Creating objects in template using "new" keyword
Date Thu, 03 Mar 2005 06:33:47 GMT
Hi Ravikanth,

> I would like to create a object reference in template using "new"
> keyword like what we do in java
> String obj = new String()
> I need to put RenderTool instance in context and use it to fix some
> problem. I know that i can put it to context from the java code where
> the template is being called or using toolbox.xml  But as my
> application is standalone and in production and i don't want to change
> the java code to fix the issue, i want to handle it in template.

If you really, really, really want to do it, check out the deprecated

Or, you can call Class#newInstance from anywhere.
See Will's HackingVelocity power point about how to do this.
## Under "An Evil Velocity Template"

> And also is there any way to get the reference to the context in
> templates when Velocity.mergeTemplate() is being used, though the
> context reference is not kept in context.

None that I know of.

> Is it possible to achieve this ? Any suggestions are most welcome.

What would be the risks of adding the two lines to your java code?  If
none of the templates already use the references "$render" or "$ctx",
then I think you can update it without much worry.

I also think there was a post in bugzilla some while ago about a
toolbox for standalone apps.

Best regards,
-- Shinobu

Shinobu Kawai <>

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

View raw message