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
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
Sheriff

Joined: Jul 29, 2008
Posts: 3435
    
  65

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
Sheriff

Joined: Jul 29, 2008
Posts: 3435
    
  65

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

Yep, that was a typo
 
 
subject: Creating dynamic EL Method Expressions?