You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Thilo Schwidurski <th...@web.de> on 2003/02/18 18:55:52 UTC

Metaprogramming and Velocity

Dear v-users,

I want to loop over a set of bean property names (kinda like this approach,
which actually doesn't work):

#foreach( $property in $properties )
    <td>$person.$property</td>
#end


and have velocity interpreted it as this statements:

    <td>$person.Name</td>
    <td>$person.EMail</td>
    <td>$person.Address</td>


Well, I guess you now what I want. (How) could this be done?

Regards,
Thilo.





---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Metaprogramming and Velocity

Posted by Thilo Schwidurski <th...@web.de>.
"Attila Szegedi" <sz...@freemail.hu> schrieb im Newsbeitrag
news:02a101c2d793$fec653d0$57595f50@caesar...
> I doubt that solves Thilo's problem.
>
> He wants to be able to iterate over available properties, and output each
> property value in turn.

Almost, I think. I am not sure if this got clear, but the array of
properties is something that I want to define in the VTL-file. I don't need
introspection here to get a bean's available properties (that is how I
unterstood your statement above). To show my intentions clearer the snippet
probably should look like this:

#set( $properties = ["Name", "EMail", "Address"] )

#foreach( $property in $properties )
    <td>$person.$property</td>
#end

> He would need the equivalent of the below code snippet in FM, assuming
> "person" is an extended hash in FM terminology (I know you're fluent in FM
> template language, that's why I dare to post a FM snippet to illustrate
the
> problem. Frankly, I don't have a clue how do you achieve this with
> Velocity):
>
> <foreach property in person?keys>
>   ${person[property]}
> </foreach>
>
> So, if you know how to do it in VTL, please share it with us. I think
that's
> what Thilo is looking for.
>
> Attila.

With his reply Denis gave me the proper keywords for a successful search in
the archive, so this looks like the solution:

http://www.mail-archive.com/velocity-user@jakarta.apache.org/msg08265.html

Thank you, Attila and Denis!

Regards,
Thilo.




---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Metaprogramming and Velocity

Posted by Attila Szegedi <sz...@freemail.hu>.
I doubt that solves Thilo's problem.

He wants to be able to iterate over available properties, and output each
property value in turn.
He would need the equivalent of the below code snippet in FM, assuming
"person" is an extended hash in FM terminology (I know you're fluent in FM
template language, that's why I dare to post a FM snippet to illustrate the
problem. Frankly, I don't have a clue how do you achieve this with
Velocity):

<foreach property in person?keys>
  ${person[property]}
</foreach>

So, if you know how to do it in VTL, please share it with us. I think that's
what Thilo is looking for.

Attila.

----- Original Message -----
From: "Denis" <br...@mac.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Tuesday, February 18, 2003 9:53 PM
Subject: Re: Metaprogramming and Velocity


Thilo,

I would suggest looking at the archives as this was answered at
different times.

The solution is to expose Velocity.evaluate() via a tool and use it
with:

#set ($obj = '$person.') #* Note the single quotes *#
$tool.eval("$obj$property")

Hope this helps,
-- Denis.

mardi 18 février 2003, à 05:55  pm, Thilo Schwidurski a écrit :

> Dear v-users,
>
> I want to loop over a set of bean property names (kinda like this
> approach,
> which actually doesn't work):
>
> #foreach( $property in $properties )
>     <td>$person.$property</td>
> #end
>
>
> and have velocity interpreted it as this statements:
>
>     <td>$person.Name</td>
>     <td>$person.EMail</td>
>     <td>$person.Address</td>
>
>
> Well, I guess you now what I want. (How) could this be done?
>
> Regards,
> Thilo.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Metaprogramming and Velocity

Posted by Denis <br...@mac.com>.
Thilo,

I would suggest looking at the archives as this was answered at 
different times.

The solution is to expose Velocity.evaluate() via a tool and use it 
with:

#set ($obj = '$person.') #* Note the single quotes *#
$tool.eval("$obj$property")

Hope this helps,
-- Denis.

mardi 18 février 2003, à 05:55  pm, Thilo Schwidurski a écrit :

> Dear v-users,
>
> I want to loop over a set of bean property names (kinda like this 
> approach,
> which actually doesn't work):
>
> #foreach( $property in $properties )
>     <td>$person.$property</td>
> #end
>
>
> and have velocity interpreted it as this statements:
>
>     <td>$person.Name</td>
>     <td>$person.EMail</td>
>     <td>$person.Address</td>
>
>
> Well, I guess you now what I want. (How) could this be done?
>
> Regards,
> Thilo.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org