You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Krishnan Muthuswamy <kr...@hotmail.com> on 2004/08/05 00:08:16 UTC
Is there anyway I can access a static method from a Velocity Template?
I have my Renderer as a standalone Java Class. This Java class kicks of
rendering of Composites. Composites in turn kick off rendering Components.
Now in my layout template I would like call back the Renderer. Even though
all the methods in the Renderer are static, I still have to create an
instance of the Renderer and put it in the context for the VTL to get access
to this object.
Is there a way around it? I made renderer stateless to precisely avoid
creating multiple instances.
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Is there anyway I can access a static method from a Velocity Template?
Posted by Shinobu Kawai <sh...@ieee.org>.
Hi Krishnan,
> I have my Renderer as a standalone Java Class. This Java class kicks of
> rendering of Composites. Composites in turn kick off rendering Components.
> Now in my layout template I would like call back the Renderer. Even though
> all the methods in the Renderer are static, I still have to create an
> instance of the Renderer and put it in the context for the VTL to get access
> to this object.
> Is there a way around it? I made renderer stateless to precisely avoid
> creating multiple instances.
How about making it a Singleton?
Actually, I have never came across a situation where creating multiple
instances became an issue. You can think of it as a MonoState, with no
state.
Best regards,
-- Shinobu Kawai
--
Shinobu Kawai <shinobu@ieee.org, shinobu@computer.org>
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Is there anyway I can access a static method from a Velocity
Template?
Posted by Nathan Bubna <na...@esha.com>.
Krishnan Muthuswamy said:
> I have my Renderer as a standalone Java Class. This Java class kicks of
> rendering of Composites. Composites in turn kick off rendering Components.
> Now in my layout template I would like call back the Renderer. Even though
> all the methods in the Renderer are static, I still have to create an
> instance of the Renderer and put it in the context for the VTL to get access
> to this object.
> Is there a way around it? I made renderer stateless to precisely avoid
> creating multiple instances.
<answer type="canned">Use A Tool (tm)</answer>
<example>
public class MyTool {
public Foo getFoo(String bar) {
return Renderer.getFoo(bar);
}
}
</example>
Nathan Bubna
nathan@esha.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org