I was really hoping no one would actually try to make that work ;-) It's really not recommended practice.

I'd follow Christopher's advice and print each intermediate step to debug it, see which piece works. Look at the reflection API for more info.

Hope you found the slides useful.

WILL


----- Original Message ----- From: "Ravikanth L" <[EMAIL PROTECTED]>
To: "Velocity Users List" <[email protected]>
Sent: Friday, September 16, 2005 4:19 AM
Subject: Re: Hacking Velocity


Hi Will,
I was trying the following example (to create a custom class instance
dynamically in the template) given in the slides
 ## Let's do some mischief and instantiate an arbitrary class
#set ($fileclass = $obj.Class.forName("java.io.File"))
#set ($stringclass = $obj.Class.forName("java.lang.String"))
#set ($paramlist = [".."])
#set ($paramarray = $paramlist.toArray())
#set ($constructors = $fileclass.constructors)
## Call the constructor java.io.File(String)
#foreach ($c in $constructors)
#if ($c.toString() == "public java.io.File(java.lang.String)")
#set ($file = $c.newInstance($paramarray))
$file
#end
#end

where $obj is any object instance. I am neither getting the output nor its
giving any error in the velocity log. I am using default introspector, not
changed anything. Does the deault introspector allows to create
newinstance() etc from template?
Am i missing anything else otherwise?
Regards,
Ravi
On 12/7/04, Will Glass-Husain <[EMAIL PROTECTED]> wrote:

Thanks for the pointer to my slides from ApacheCon ("Hacking Velocity").

For the record there are slides and sample code available on these topics:

--> VelocityViewServlet
--> Custom directives
--> Custom resource loaders
--> Event handlers
--> Custom introspector
--> Modifying Velocity syntax with JavaCC

I've put the material on the Wiki for more general availability. Hope this
is useful to other users.
http://wiki.apache.org/jakarta-velocity/HackingVelocity

Best, WILL

----- Original Message -----
From: "Shinobu Kawai" <[EMAIL PROTECTED]>
To: "Velocity Users List" <[email protected]>
Sent: Monday, December 06, 2004 2:12 PM
Subject: Re: [FAQ] How do you check for null?


> Hi Henning,
>
>> With the slides from Will's talk @ ApacheCon, you should be able to
>> add a new statement to the VTL so you can do
>>
>> #ifnull($car.fuel)
>
> Hey, thanks for the idea! Approach #6 : use a custom directive. :)
> I'll look into that.
>
> Best regards,
> -- Shinobu Kawai
>
> --
> Shinobu Kawai <[EMAIL PROTECTED]>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to