You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jeb Boniakowski <jb...@nntllc.com> on 2001/08/16 19:58:08 UTC

evaluation of references w/r/t macros

Please excuse this lengthy, code-ridden post.  I don't understand how
references to objects are passed with to macros.  I had assumed that the
velocity processor would simply take the macro code, paste it in place of
the macro call, and substitue the reference minus the quotes in
appropriately, so that at some point, a situation like this:

#macro(monkey $bar )
 $bar $bar $bar
#end
#monkey( "$robot" )

would get transformed into
 $robot $robot $robot

However, this does not seem to be the case.
I only want to be able to do one simple thing.

Let's say I have a class like this:

public class Test extends VelocityScreen{
    public class Foo{
 String baz;
 public Foo(){ baz = "bazbazbaz"; }
 public String getBaz(){ return baz; }
    }

    public class Bar{
 Foo f;
 public Bar(){ f = new Foo(); }
 public Foo getFoo(){ return f; }
    }

    public void doBuildTemplate( RunData data, Context context ){
 Bar b = new Bar();
 context.put("bar", b);
    }
}// Test

And I have a Test.vm like this:

 Bar: $bar <p>
 Bar.getFoo(): $bar.getFoo() <p>
 Bar.getFoo().getBaz(): $bar.getFoo().getBaz() <p>

Macro version: <p>
#macro( testMac $bar )
 Bar: $bar <p>
 Bar.getFoo(): $bar.getFoo() <p>
 Bar.getFoo().getBaz(): $bar.getFoo().getBaz() <p>
#end
#testMac( "$bar" )

The output will be like this:

Bar: com.nntllc.real.modules.screens.Test$Bar@3e58d4
Bar.getFoo(): com.nntllc.real.modules.screens.Test$Foo@661fd1
Bar.getFoo().getBaz(): bazbazbaz

Macro version:
Bar: $bar
Bar.getFoo(): $bar.getFoo()
Bar.getFoo().getBaz(): $bar.getFoo().getBaz()

I want the macro version output to look like the output above.  How do I do
that?

jeb.


RE: evaluation of references w/r/t macros

Posted by Paulo Gaspar <pa...@krankikom.de>.
But the usual suspect is innocent... 
=;o)

Paulo

> -----Original Message-----
> From: Tim Colson [mailto:tcolson@cisco.com]
> Sent: Thursday, August 16, 2001 9:03 PM
> 
> > > Well jeb, I'd have to say you are an unqualified moron.
> It's a good thing I read the complete email...
> 
> After that first sentence, I was going to reply to Jon and tell him to
> lighten up on the guy. ;-) <grin>
> 
> Tim
> 

RE: evaluation of references w/r/t macros

Posted by Tim Colson <tc...@cisco.com>.
> > Well jeb, I'd have to say you are an unqualified moron.
It's a good thing I read the complete email...

After that first sentence, I was going to reply to Jon and tell him to
lighten up on the guy. ;-) <grin>

Tim


Re: evaluation of references w/r/t macros

Posted by Jon Stevens <jo...@latchkey.com>.
on 8/16/01 11:27 AM, "Jeb Boniakowski" <jb...@nntllc.com> wrote:

> Well jeb, I'd have to say you are an unqualified moron.  Why did you put
> those quotes around $bar?  That's your whole problem right there.  What, did
> you think it was like ` in scheme and if you didn't do it, that would get
> evaluated right there, leaving the result of $bar.toString() in it's place.
> It's VTL, jeb, not scheme, read the manual before you post to the mailing
> list more closely next time.  It's all in there.  Idiot.
> 
> jeb.

It's cute how you talk to yourself in public. :-)

-jon


Re: evaluation of references w/r/t macros

Posted by Jeb Boniakowski <jb...@nntllc.com>.
Well jeb, I'd have to say you are an unqualified moron.  Why did you put
those quotes around $bar?  That's your whole problem right there.  What, did
you think it was like ` in scheme and if you didn't do it, that would get
evaluated right there, leaving the result of $bar.toString() in it's place.
It's VTL, jeb, not scheme, read the manual before you post to the mailing
list more closely next time.  It's all in there.  Idiot.

jeb.

----- Original Message -----
From: Jeb Boniakowski <jb...@nntllc.com>
To: <ve...@jakarta.apache.org>
Sent: Thursday, August 16, 2001 1:58 PM
Subject: evaluation of references w/r/t macros


> Please excuse this lengthy, code-ridden post.  I don't understand how
> references to objects are passed with to macros.  I had assumed that the
> velocity processor would simply take the macro code, paste it in place of
> the macro call, and substitue the reference minus the quotes in
> appropriately, so that at some point, a situation like this:
>
> #macro(monkey $bar )
>  $bar $bar $bar
> #end
> #monkey( "$robot" )
>
> would get transformed into
>  $robot $robot $robot
>
> However, this does not seem to be the case.
> I only want to be able to do one simple thing.
>
> Let's say I have a class like this:
>
> public class Test extends VelocityScreen{
>     public class Foo{
>  String baz;
>  public Foo(){ baz = "bazbazbaz"; }
>  public String getBaz(){ return baz; }
>     }
>
>     public class Bar{
>  Foo f;
>  public Bar(){ f = new Foo(); }
>  public Foo getFoo(){ return f; }
>     }
>
>     public void doBuildTemplate( RunData data, Context context ){
>  Bar b = new Bar();
>  context.put("bar", b);
>     }
> }// Test
>
> And I have a Test.vm like this:
>
>  Bar: $bar <p>
>  Bar.getFoo(): $bar.getFoo() <p>
>  Bar.getFoo().getBaz(): $bar.getFoo().getBaz() <p>
>
> Macro version: <p>
> #macro( testMac $bar )
>  Bar: $bar <p>
>  Bar.getFoo(): $bar.getFoo() <p>
>  Bar.getFoo().getBaz(): $bar.getFoo().getBaz() <p>
> #end
> #testMac( "$bar" )
>
> The output will be like this:
>
> Bar: com.nntllc.real.modules.screens.Test$Bar@3e58d4
> Bar.getFoo(): com.nntllc.real.modules.screens.Test$Foo@661fd1
> Bar.getFoo().getBaz(): bazbazbaz
>
> Macro version:
> Bar: $bar
> Bar.getFoo(): $bar.getFoo()
> Bar.getFoo().getBaz(): $bar.getFoo().getBaz()
>
> I want the macro version output to look like the output above.  How do I
do
> that?
>
> jeb.