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 Tue, 08 Oct 2002 00:04:00 GMT
Aapo,

Here is a small script, using a context tool called 'ff':

#set($test = "getSig()")
1-$ff.$test<br>
2-$ff.getSig()<br>
3-$ff.Sig<br>

Here's the output:
1-npg1.business.ff@7afa94.getSig()        ##note that this is merely a
reference
2-This is FF, your friendly formatter
3-This is FF, your friendly formatter

HTH,

Terry



----- Original Message -----
From: "Aapo Laakkonen" <aapo.laakkonen@giro.fi>
To: "'Velocity Users List'" <velocity-user@jakarta.apache.org>
Sent: Monday, October 07, 2002 7:27 PM
Subject: RE: Variable method name in a macro?


> > String propertyName = "title";
> > String evalString = "$book." + propertyName;
> > String title = tool.eval(evalString);
> >
> > The big problem I seem to be having is how
> > to pass the string "$book.title" into the
> > eval method - the eval method itself seems
> > to work fine.
>
> This is exactly what I'm after also. Here is my (more complex) example:
>
> // $data is a list (java.util.List) of beans with proper getters (and
> setters).
>
> #macro(list $data $columns)
> <table>
>   #foreach ($column in $columns)
>     <th>$tool.getText($column)</th>
>   #end
>   #foreach ($row in $data)
>   <tr>
>     #foreach ($column in $columns)
>       <td>
>         In this place I want Velocity to call following methods:
>         $data.getName().getFirst() or $data.getName().getLast().
>         eg. $tool.evaluate("$row.$column").
>       </td>
>     #end
>   </tr>
>   #end
> </table>
> #end
>
> #set($columns = ["name.first", "name.last"]
> #list($employees $columns)
>
> This way I could write html-tables with only 2-lines of code. And I
> could develop it furher to build very handy web ui-tools (with search,
> actions (update, insert, delete), sorting, paging, etc.).
>
> > So, what's the trick? Any help greatly appreciated!! :-)
>
> If you get it to work, could you send me your solution? I will look this
> thing again tomorrow and will post my solution (if I found one) here.
>
>
> --
> 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