[jelly] Dynamic variable interpolation

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[jelly] Dynamic variable interpolation

Grant Ingersoll
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [jelly] Dynamic variable interpolation

Paul Libbrecht
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [jelly] Dynamic variable interpolation

Dion Gillard-2
In reply to this post by Grant Ingersoll
On 6/9/05, Grant Ingersoll <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [jelly] Dynamic variable interpolation

Grant Ingersoll
In reply to this post by Grant Ingersoll
Nesting doesn't work, but the context trick does.   Thanks!

>>> [hidden email] 6/8/2005 4:18:56 PM >>>
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: [hidden email]
For additional commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]