tags:

views:

79

answers:

1

Is it possible to evaluate a String as EL expression in JSP and get value from it?

I need an expression like ${model.${fieldPath}} where fieldPath will contain the required object path from a nested object model.

I can get the actual field path by using but I am not sure how to evaluate a string and get the value from it

Any help regarding this would be highly appreciated.

+1  A: 

I'm not sure I understood it correctly, but I think you just need this expression:

${model[fieldPath]}

In EL dot operator and [] subscription are basically the same: different syntax, but the same access.

doublep
Thanks for your response. But in our case "fieldPath" value was pointing to a complex structure like "matrixAssumptions[assumptionId].data[rowName].data[matrixColumns[0]].percentage".When I try to use [] instead of EL dot, it is not able to find such field in the object and throws exception.
Venkatesh
@Venkatesh: What exception specifically? You should be able to put the whole expression into the brackets in `${model[...]}` if it gives a valid property name (valid for `${model}`, that is).
doublep