velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@adeptra.com>
Subject Re: summary table of velocity reflection?
Date Fri, 09 Aug 2002 19:42:11 GMT
On 8/9/02 3:35 PM, "Mark D. Anderson" <mda@discerning.com> wrote:

> I'm still hoping someone who actually knows the answer would give one, but
> here is a revised attempt at summarizing this.

I've been hoping you'd look and summarize :)

> 
> anything not public:
>  not available
>  workaround: add a public method to the class or a helper class

Yes
 
> public static variables:
>  java:  context.put("foobar", new org.apache.velocity.app.FieldMethodizer(
> "com.whatever.MyClass" ));
>  VTL:   $foobar.SOME_CONSTANT

Yep
 
> public instance variables:
>  not available
>  workaround: add a public method to the class

Yep
 
> public constructors, no args:
>  java:  context.put("ClassName", com.whatever.MyClass.class)
>  VTL:   #set ($myobj = $ClassName.newInstance())

Heh.  Never thought of that.
 
> public constructors, with args:
>  not available
>  workaround: add a public static method to the class or a helper class
> 

Yep - the idea is to provide all the objects necessary for the designer, not
let them create them.

If you are of the sort that would create them, there are tools you can use
that let you specify the classname and get a new instance.

See the vel tools subproject

> public static methods:
>  java:  context.put("ClassName", com.whatever.MyClass.class)
>  VTL:   $ClassName.doSomething()
> 
> public instance methods not starting with "get" or "set":
>  java:  MyClass obj; context.put("myobj", obj);
>  VTL:   $myobj.doSomething()

Yep, and you can call get/set directly
 
> public instance methods starting with "get" or "set":
>  java:  MyClass obj; context.put("myobj", obj);
>  VTL:   $myobj.getBar()
>         $myobj.setBar(1)
>         $myobj.bar
>         $myobj.Bar
> 

Yep

  as well as 

  #set($myobj.bar = 1)

 
And don't forget that you can also take advantage of things that look like
Map :


  $myobj.bar    could execute as    obj.get("bar")


  #set($myobj.bar = 1 could exec as obj.put("bar", value)

Where value = new Integer(1);

If you can format this into a patch for the dev guide, that would be great.

-- 
Geir Magnusson Jr. 
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713



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


Mime
View raw message