• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating dynamic EL Method Expressions?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I would like to combine the values of two different page scoped objects to create a method expression in EL.

I have a bean object "bean" which is a java bean with a number of properties (with getters and setters) and then i have a "beanProperty" object which is the name of the property whose getter i want to invoke on the "bean" object.

In the EL expression, I can "hard code" the name of the property like this: <c:out value="${bean.hardCodedNameOfProperty}"/>

But the name of the property i want to invoke on my bean is stored in my "beanProperty" variable, so what I would like to do is something like this:

<c:out value="${bean.${beanProperty}}"/>

But EL can't parse such an expression...

Does anyone know if it is even possible to achieve what I'm trying to do?

BR,

Björn
 
Sheriff
Posts: 7136
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can call it as: ${bean.[beanProperty]}
 
Björn Wessman
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Devaka Cooray wrote:You can call it as: ${bean.[beanProperty]}



Hi Devaka!

Thank you for the reply. I had to remove the dot from your example to make it work, like this:

${bean[beanProperty]}

Thanks for pointing me in the right direction, really appreciate it :)
 
Devaka Cooray
Sheriff
Posts: 7136
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Björn Wessman wrote:I had to remove the dot from your example


Yep, that was a typo
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic