velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Will Glass-Husain" <wgl...@forio.com>
Subject Re: object type casting in velocity context
Date Sun, 03 Jul 2005 01:48:25 GMT
In a word, no.  Velocity provides a lot of flexibility in that you can call 
any Java method from the template, but this means that you need to be 
careful as to which methods are available.

Best bet is to make a wrapper object and pass through the methods you are 
allowing to be called.

WILL



----- Original Message ----- 
From: "Allen Gilliland" <agilliland@gmail.com>
To: <velocity-user@jakarta.apache.org>
Sent: Saturday, July 02, 2005 3:26 PM
Subject: object type casting in velocity context


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: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


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


Mime
View raw message