You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Ravikanth.L" <ra...@yahoo.com> on 2004/08/25 09:22:07 UTC
constructing dynamic variables from the available data
Hi,
I am very new to this velocity framework. Could
anyone please let me know how to dynamically create
variables and use them.
The scenario is:
I have an object in context which will give the
names of all variables and a hashmap with this
variable name as key and value. I already have a
template which is using the variable names. I need to
dynamically construct the variables and set it to
context( in template only not from java) so that, the
tempalte can use it.
for eg:
$elementList contains a arrayList of all Element
object from which I can get the name of the element
and
I should be able to create a variable using #set for
that element and assign the value from the hashmap
object.
Any suggestions are welcome.
With Regards,
Ravikanth.L
__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: constructing dynamic variables from the available data
Posted by Simon Christian <si...@stoutstick.com>.
Question: if you don't know what the element names are going to be, how
are you going to know to use them? Conversely if you do know which ones
are available (or more precisely which ones you want) and are happy to
override them, why not just set them directly e.g.
#set( $name = $myElementValues.get( "name" ) )
or even
#set( $name = $myElementValues.name )
Alternatively if you really don't know and don't care what the element
names are, I can only imagine you're intending to list them all out
somehow in which case you can do something like:
#foreach( $element in $myElementNames )
Name: $element Value: $myElementValues.get( $element )
#end
Sorry if I'm missing something obvious here.
- simon
Ravikanth.L wrote:
> Hi,
>
> I am very new to this velocity framework. Could
> anyone please let me know how to dynamically create
> variables and use them.
>
> The scenario is:
>
> I have an object in context which will give the
> names of all variables and a hashmap with this
> variable name as key and value. I already have a
> template which is using the variable names. I need to
> dynamically construct the variables and set it to
> context( in template only not from java) so that, the
> tempalte can use it.
>
> for eg:
> $elementList contains a arrayList of all Element
> object from which I can get the name of the element
> and
> I should be able to create a variable using #set for
> that element and assign the value from the hashmap
> object.
>
> Any suggestions are welcome.
>
> With Regards,
> Ravikanth.L
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - 50x more storage than other providers!
> http://promotions.yahoo.com/new_mail
>
> ---------------------------------------------------------------------
> 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