velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aapo Laakkonen" <>
Subject RE: Variable method name in a macro?
Date Mon, 07 Oct 2002 23:27:31 GMT
> 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

#macro(list $data $columns)
  #foreach ($column in $columns)
  #foreach ($row in $data)
    #foreach ($column in $columns)
        In this place I want Velocity to call following methods:
        $data.getName().getFirst() or $data.getName().getLast().
        eg. $tool.evaluate("$row.$column").

#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:   <>
For additional commands, e-mail: <>

View raw message