Noooooo... #set($newobject = $foo.class.forName("myclass").newInstance())
is just not a good way of doing this. It's error-prone, hard to read, may not be supported in future versions of Velocity. Instead, create an instance of the object and put it into the context before Velocity is called with context.put("newobject", new MyClass()); Note to Claude: I've got a new (simpler) Uberspector subclass that addresses this. I'm going to integrate it into 1.5 during our Hackathon in two weeks. WILL On 9/29/06, Claude Brisson <[EMAIL PROTECTED]> wrote:
Do you mean : "How to put a new instance of a class in the velocity context from inside the vtl?" Usually, you put classes in the context using java (context.put("name",object)), or using toolbox.xml if you rely on the VelocityTools subproject. Now, if you really want to load a new instance of a class in the context from inside the VTL, you have the following hack: #set($newobject = $foo.class.forName("myclass").newInstance()) where $foo can be any existing reference. But this is really not a very clean coding style... Also, the class you load must have a default constructor (otherwise it is still possible but more complex). By the way, dev people, why is this issue only scheduled for 1.6? Will's patch seems to be ready in http://issues.apache.org/jira/browse/VELOCITY-179 and backward compatible with proper default configuration value. Claude Le vendredi 29 septembre 2006 à 10:27 -0400, sandesh makam a écrit : > hi, > Can any body tell me how i can call a class in a velocity template. > I am trying to write a template which call a class that allows me to build > a tree. > > thankyou --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Forio Business Simulations Will Glass-Husain [EMAIL PROTECTED] www.forio.com --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]