velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph.R...@dlr.de
Subject Re: calling arbitrary methods from within template
Date Fri, 13 Dec 2002 15:30:44 GMT
Hello,

you *can* call arbitrary methods on objects that are in the context.
To take up your examples, they should state:
	$foo.printMessage("...")
	$bar.pushRock(myRock)
assuming you placed the $foo and $bar objects with those methods into
the context and the class and its methods allow public access.

You can create a convenience macro if you just want to call the
method ignoring the return value:
	#macro(call $param)#if($param)#**##end#end
Using an if-statement avoid any log messages if the call returns
null. But be warned, I do not know what happens if the method
call returns an exception.

Cheers,
Christoph

Jan Geiger wrote:
> Hi,
> 
> I'd like to call arbitrary-named methods from a velocity template, e.g.
> printMessage("...") or pushRock(myRock) (just referring to the user's guide ...).
> Unfortunately Velocity always seems to assume that I'm using
> property-accessor methods (i.e. getters and setters). Is there a possibility to call
such
> arbitrary-named methods and further use their return values (which would be
> calculated whilst method-execution) or do I have to use "Prepared Objects" which
> I put into the Velocity-context and which contain the data I want to access
> in a JavaBeans-like manner (i.e. I have to setup them in my java programs)?
> 
> The background for wanting to call arbitrary-named methods is that I have to
> access the data I must process from an UML repository (Novosoft) where all
> necessary information is neatly stored, but not always in a JavaBeans-like
> manner.
> 
> Thanks for all replies,
> 
> Jan Geiger
> 

-- 
:) Christoph Reck


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


Mime
View raw message