As far as I know it is not possible to do it as EL is going to take the
[fieldname] to be a static string referencing your fieldname attribute.
Thus, EL just tries to map that to entity.getAddress.street() which would be
invalid or find an element 'address.street' within a hash map.  I believe if
your entity actually returned a HashMap, then you would be fine, but with
just a standard POJO, it is not directly possible.

However, I am in the need of something similar and have been planning on
just writing my own EL resolver such that I would tokenize the 'x.y' string
when the subject is a POJO and then lookup each property accordingly on the
object such as obj.getX().getY().  You may need to do something similar in
you case.

Although, if anyone else has any good suggestions on how to do this better
or more efficiently, I would love to hear before I embark on my quest to
code it myself. :)

Thanks,
Nick

-----Original Message-----
From: r.stranders [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 20, 2007 4:52 PM
To: [email protected]
Subject: Re: Navigate nested beans


Your code is correct. I would like to generalize accessing the properties of
an entity by with facelets using a construct like #{contact[name]} or
#{contact[address.street]}. The former works, the latter gives an exception.
I don't think this has anything to do with facelets.


Mike Kienenberger wrote:
> 
> How would you do it if there were no facelets tag involved?
> 
> In my own code, it's #{contact.address.street} --
> Contact.getAddress().getStreet().
> 
> Without knowing your datastructure, we can't give you an answer.
> 
> 
> On 3/20/07, r.stranders <[EMAIL PROTECTED]> wrote:
>>
>> Hi,
>>
>> I've got a generic facelet for outputting attributes of an entity called
>> outputField.xhtml. Its definition:
>> <ui:composition>
>>     ...
>>     <h:outputText value="#{entity[fieldName]}" />
>> </ui:composition>
>>
>> Example usage: <outputField entity="contact" fieldName="firstName" />
>>
>> However, the entity "contact" also has an composite attribute "address"
>> which has attributes itself. However when I try: <outputField
>> entity="contact" fieldName="address.street" />. I get an exception. Any
>> idea
>> how I can access the nested bean in this generic way? (i.e.
>> entity[fieldName])?
>> --
>> View this message in context:
>> http://www.nabble.com/Navigate-nested-beans-tf3436593.html#a9581797
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context:
http://www.nabble.com/Navigate-nested-beans-tf3436593.html#a9582492
Sent from the MyFaces - Users mailing list archive at Nabble.com.

Reply via email to