velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Terry Steichen" <te...@net-frame.com>
Subject Re: Variable method name in a macro?
Date Mon, 07 Oct 2002 16:01:58 GMT
Chris,

Is 'propertyName' the name of a public method, or is it a property?

Is this VTL code in a macro or in the main template body?

Curiosity: (1) why the single quotes around 'propertyName', and (2) why the
'\' in "\$option..$method"?

Regards,

Terry

----- Original Message -----
From: "Chris Miller" <chris@swebtec.com>
To: <velocity-user@jakarta.apache.org>
Sent: Monday, October 07, 2002 10:40 AM
Subject: Re: Variable method name in a macro?


> Does anyone have any comments on this? I must be missing something simple.
>
> "Chris Miller" <chris@swebtec.com> wrote in message
> news:amtefe$52c$1@main.gmane.org...
> > First off, I had a look around the CVS contrib dirs and the Tools
> > subproject, but still couldn't see your tool code.
> >
> > I've been trying to implement this myself. However I'm still missing
> either
> > a vital piece of information, or, more likely, a vital piece of my
brain.
> >
> > I am trying to achieve something like the following:
> >
> > #set($method = 'propertyName')
> > #foreach($option in $list)
> >     $tool.eval("\$option.$method")
> > #end
> >
> > So far I have the following code in my tool:
> >
> >    public String eval(String str) throws Exception
> >    {
> >        StringWriter writer = new StringWriter(100);
> >        Velocity.evaluate(context, writer, "postEval", str);
> >        return writer.toString();
> >    }
> >
> > Note that I pass the context into the tool's constructor, and then put
the
> > tool into the context before merging my original template :-)
> >
> > This however still does not work - the eval() method does not get
called.
> > I've also tried using $tool.eval("\option.get$method()"), which doesn't
> even
> > parse properly. Any tips on what I'm still missing?
> >
> > Thanks,
> > Chris
> >
> >
> > > 2) Velocity doesn't do evaluation interpolation for introspection
(that
> > > phrase may not make sense?)
> > >
> > >    $formBean.$method
> > >
> > > does *not* work.
> > >
> > > However, you can easily make a tool (I have said this same thing 3-4
> times
> > > this week - I am going to just write it and put in contrib at this
point
> > to
> > > prove my learning curve isn't flat) where you *can* do
> > >
> > >   $tool.eval("\$formBean.get$which()")
> > >
> > > such that the eval(String) method gets, with $which -> "FirstName",
> > >
> > >    $formBean.getFirstName()
> > >
> > > and then your tool can just evaluate that against the context.
> > >
> > > Does that make sense?
> > >
> > > --
> > > 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>
>
>


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