You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "r.stranders" <r....@gmail.com> on 2007/03/20 22:12:02 UTC

Navigate nested beans

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.


Re: Navigate nested beans

Posted by Jonathan Harley <jo...@parkplatz.net>.
Having suggested someone look at making a custom property resolver
myself last week, I was thinking about this, and I suspect that EL
is *deliberately* designed not to allow this. It's actually a bad
idea to code all that internal structure of objects into the view,
because it's a poor level of encapsulation. Exposing all that
structure breaks the "Law of Demeter".

In the example below, if a contact's street is needed in the view,
then Contact itself should have a getStreet() accessor - which may
delegate to an Address object *currently*, but then you'd be free
to change that implementation later. And then EL would have no
problem with #{contact[street]}.

-Jonathan.

Mike Kienenberger wrote:
> Right, I see now what you're saying and why my answer is not of any help 
> :-)
> Yes, it's entirely determined by the EL.   Have you tried reading
> through the unified EL spec to see if there's anything helpful in
> there?  I thought I had older email that dealt with this topic, but
> apparently it's the same thing you're basing your question on, so I
> doubt it's of any help:
> http://www-128.ibm.com/developerworks/java/library/j-facelets/#N103EC
> 
> I guess you could create a custom property resolver if you don't find
> anything.   A property resolver would definitely work, but would
> probably be a lot of work.
> 
> On 3/20/07, r.stranders <r....@gmail.com> wrote:
>>
>> 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.

-- 
.....................................................................
           Dr Jonathan Harley   .
                                .   Email: jon@parkplatz.net
            Zac Parkplatz Ltd   .   Office Telephone: 024 7633 1375
            www.parkplatz.net   .   Mobile: 079 4116 0423

Re: Navigate nested beans

Posted by Mike Kienenberger <mk...@gmail.com>.
Right, I see now what you're saying and why my answer is not of any help :-)
Yes, it's entirely determined by the EL.   Have you tried reading
through the unified EL spec to see if there's anything helpful in
there?  I thought I had older email that dealt with this topic, but
apparently it's the same thing you're basing your question on, so I
doubt it's of any help:
http://www-128.ibm.com/developerworks/java/library/j-facelets/#N103EC

I guess you could create a custom property resolver if you don't find
anything.   A property resolver would definitely work, but would
probably be a lot of work.

On 3/20/07, r.stranders <r....@gmail.com> wrote:
>
> 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 <r....@gmail.com> 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.
>
>

Re: Navigate nested beans

Posted by Mike Kienenberger <mk...@gmail.com>.
Right, I see now what you're saying and why my answer is not of any help :-)
Yes, it's entirely determined by the EL.   Have you tried reading
through the unified EL spec to see if there's anything helpful in
there?   I suspect entity[field] works more by accident than by
design.

On 3/20/07, r.stranders <r....@gmail.com> wrote:
>
> 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 <r....@gmail.com> 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.
>
>

Re: Navigate nested beans

Posted by "r.stranders" <r....@gmail.com>.
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 <r....@gmail.com> 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.


Re: Navigate nested beans

Posted by Mike Kienenberger <mk...@gmail.com>.
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 <r....@gmail.com> 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.
>
>