This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Creating dynamic EL Method Expressions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Creating dynamic EL Method Expressions?" Watch "Creating dynamic EL Method Expressions?" New topic
Author

Creating dynamic EL Method Expressions?

Björn Wessman
Greenhorn

Joined: Jun 01, 2009
Posts: 21
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
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3029
    
  35

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


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Björn Wessman
Greenhorn

Joined: Jun 01, 2009
Posts: 21
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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3029
    
  35

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

Yep, that was a typo
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating dynamic EL Method Expressions?
 
Similar Threads
Populating a List using JSTL and spring MVC
EL expression evaluation
EL expression evaluation
"target" version of c:set
evaluate dynamic expression language