File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets 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: 3013
    
  35

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


Founder of ExamLab and Systemup
See how I can help you to become an awesome programmer
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: 3013
    
  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
"target" version of c:set
evaluate dynamic expression language
EL expression evaluation