You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Hanlon, Jim" <ha...@netperceptions.com> on 2001/06/14 22:18:36 UTC

Invoking a static method

Is it possible to invoke a static method on a class within an expression. If
so, how?

For example:

#set($arg = "an argument")
#set($o = MyClass.getInstance($arg))
	.
	.
	.


Thanks

--
Jim Hanlon



Re: Invoking a static method

Posted by Jon Stevens <jo...@latchkey.com>.
on 6/14/01 1:18 PM, "Hanlon, Jim" <ha...@netperceptions.com> wrote:

> Is it possible to invoke a static method on a class within an expression. If
> so, how?
> 
> For example:
> 
> #set($arg = "an argument")
> #set($o = MyClass.getInstance($arg))
> .
> .
> .

context.put("MyClass", new MyClass())
#set($arg = "an argument")
#set($o = $MyClass.getInstance($arg))

In other words, any object in the context is available as a $variable.
Methods on that object can be static.

Note: Your design, IMHO, is breaking MVC. Instantiating objects for the
purpose of use within the template is bad.

-jon