velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wm Muir" <mui...@hotmail.com>
Subject Referencing Object / Class Variables
Date Tue, 20 Dec 2005 00:09:03 GMT
Greetings,

I am a WebMacro user, trying out Velocity.  Can you reference Object / Class
variables from within the template like WebMacro?  I have read over the
documentation, and have tried it myself, but no luck.

For Example:

// Object or Class
public class Foo {
   public static final String CAT = "Cat";
   public String dog = "Dog";
   ...
}

// Code
   Foo foo = new Foo();
   context.put( "fooObject", foo );
   context.put( "FooClass", Foo.class );


// Template
$fooObject
$FooClass
$fooObject.CAT
$fooObject.dog
$fooClass.CAT

This results in:
com.test.Foo@f346dc   	// expect this
class com.test.Foo    	// expect this
$fooObject.CAT		// I would expect 'Cat'
$fooObject.dog		// I would expect 'Dog'
$fooClass.CAT		// I would expect 'Cat'

---------------------------------------------------------------------
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