velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Allen Gilliland <>
Subject object type casting in velocity context
Date Sat, 02 Jul 2005 22:26:49 GMT
Hopefully this hasn't been asked a million times before, but I didn't
seen anything that asked this exact question from my search of the
list archives.

So, is there a way to control the object type of something in the
velocity context?  basically i would like to down cast some of my
objects into parent classes or interfaces so that i can limit what
methods are available inside templates.

an example would be ...

// safe version
public class FooObject {
   public String getXXX();
   public String getYYY();

// complete version
public class FooObjectImpl extends FooObject {
   public String getXXX() {}
   public String getYYY() {}
   public void setXXX(String x) {}
   public void setYYY(String y) {}
   public void save() {}
   public void remove() {}

then when i am dealing with velocity i can do this ...

FooObjectImpl fooInstance = new FooObjectImpl();
context.put("foo", (FooObject) fooInstance);

this would be extremely valuable to me because it would allow me to
use my existing set of pojos without exposting setXXX() or other
potentially dangerous public methods to template writers.

has anyone done something like this before?  maybe something like this? ...

// ( name, Object, cast to object type);
context.put("foo", fooInstance, FooObject.class);

-- Allen

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message