• 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

EL nested usage

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem to use EL to display nested properties.
suppose I have a beanA, and beanB; beanA contains beanB, and beanB has property propA.
if I want to display propA, I can use
<h:outputText value='#{beanA.beanB.propA}'/>

however if beanA has other beans, and I want to display those beans dynamically, I will take the "beanB.propA" part as a dynamic variable.

of course I can't use <h:outputText value='#{beanA.beanX.propX}'/>, as beanX.propX is not a static string. I tried <h:outputText value='#{beanA[beanX.propX]}'/> as well, it can't automatically get the second level from beanX.

anyone can help me?
[ July 06, 2006: Message edited by: Daoyue Ming ]
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll let you in on a secret. All this stuff is handled by the Apache beanutils, which is a general-purpose library that allows you to do an extended set of the kinds of functions that Java's introspection mechanism supports. It also supports accessing data via expressions such as the ones you've listed. You can find details about beanutils at http://jakarta.apache.org/commons/beanutils/ .

But as a quick guide, reading a value from "beanA.beanX.propX" is the same thing as the java code "beanA.getBeanX().getPropX()".

If I haven't confused myself, I think that your use of square brackets in the expression '#{beanA[beanX.propX]}' is wrong though - that's for array indexing. So what you probably want is more like "#{beanA(beanX).propX}". Note that this means "beanA.get(beanX).getPropX()", where "propX" is a property of the value object returned from a collection where "beanX" is a key object. As opposed to ""#{beanA(beanX.propX)}" which is "beanA.get(beanX.getPropX())".
[ July 06, 2006: Message edited by: Tim Holloway ]
 
Daoyue Ming
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can use #{beanA[beanX.propX]} if propX is primitive type, but if it is another class, it doesn't work.

I have tried your solution, doesn't work either
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the outcome of your expression must ultimately become a String or a primitive - you can't use the EL to return a compound object.

If you want to enumerate properties, you'll have to set things up so that the subproperties are each presented as simple objects. In JSF this may be a pain, since you can't embed looping constructs in JSF, only wrap collections and use the table components.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic