You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Grant Ingersoll <GS...@syr.edu> on 2005/06/08 21:41:31 UTC
[jelly] Dynamic variable interpolation
Hi,
Am a fairly new user of Jelly and am wondering if there is a way to use
the value of a variable as the name of a new variable which I can then
dereference in my script.
Something like:
<j:set var="foo" value="a,b,c"/>
<j:set var="a.name" value="A"/>
<j:set var="b.name" value="B"/>
<j:set var="c.name" value="C"/>
<util:tokenize var="vars" delim=",">
${foo}
</util:tokenize>
<j:forEach var="var" varStatus="status" items="${vars.iterator()}">
echo ${ ${var}.name }
<-------------------- what is the syntax for this???
</j:forEach>
Output would be:
A
B
C
Do I use a dynabean?
Thanks,
Grant
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [jelly] Dynamic variable interpolation
Posted by Paul Libbrecht <pa...@activemath.org>.
I doubt nested JEXL expressions would work... try it!
However, the context variable is here for you so that
${context.getVariable(name)}
should do the job in a clean way, I believe.
Tell us if it helps.
paul
Le 8 juin 05, à 21:41, Grant Ingersoll a écrit :
> <util:tokenize var="vars" delim=",">
> ${foo}
> </util:tokenize>
> <j:forEach var="var" varStatus="status" items="${vars.iterator()}">
> echo ${ ${var}.name }
> <-------------------- what is the syntax for this???
>
> </j:forEach>
>
>
> Output would be:
> A
> B
> C
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [jelly] Dynamic variable interpolation
Posted by Dion Gillard <di...@gmail.com>.
On 6/9/05, Grant Ingersoll <GS...@syr.edu> wrote:
> Hi,
>
> Am a fairly new user of Jelly and am wondering if there is a way to use
> the value of a variable as the name of a new variable which I can then
> dereference in my script.
>
> Something like:
>
> <j:set var="foo" value="a,b,c"/>
> <j:set var="a.name" value="A"/>
> <j:set var="b.name" value="B"/>
> <j:set var="c.name" value="C"/>
>
>
>
> <util:tokenize var="vars" delim=",">
> ${foo}
> </util:tokenize>
> <j:forEach var="var" varStatus="status" items="${vars.iterator()}">
> echo ${ ${var}.name }
> <-------------------- what is the syntax for this???
echo ${context.getVariable(var + '.name')}
should do it.
>
> </j:forEach>
>
>
> Output would be:
> A
> B
> C
>
> Do I use a dynabean?
>
> Thanks,
> Grant
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
--
http://www.multitask.com.au/people/dion/
"You are going to let the fear of poverty govern your life and your
reward will be that you will eat, but you will not live." - George
Bernard Shaw
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org