Ben Anderson wrote:

Hi,
I want to dynamically set which property I access. Is this possible? Obviously the below code won't work, but you get the idea. I thought
maybe that the <j:expr> tag might help, but it doesn't seem to do
anything.


   <j:set var="color" value="red"/>
   <j:set var="colorKey" value="color"/>
   <ant:echo>
       ${${colorKey}}
   </ant:echo>
Any ideas?



Maybe if I'm right hehe - try this and if it makes things work:

<j:set var="colorKey" value="${context.getVariable(color)}"/>

or rather this would return "red":

<ant:echo>
    ${context.getVariable(colorKey)}
</ant:echo>

You could chain these calls too in the JEXL expression too if you had multiple levels of indirection.

Well guess it does not fit exactly this example which you point out further down in this thread. However I'm thinking what you want to do is dynamically assemble a key value by resolving anther key. I do this for properties that associate values of an object like so:

a.b.c.name=someobj
a.b.c.class=CLI
a.b.c.package=org.apache.maven
a.b.c.interfaces=.....

I assemble these keys and look up their respective values using this technique.

Cheers,
Alex

Thanks,
Ben

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to