velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aapo Laakkonen" <aapo.laakko...@giro.fi>
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
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>


Mime
View raw message