You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by David Delbecq <de...@oma.be> on 2006/07/24 16:06:42 UTC

expression language and access of collection properties, howto

Hello,

according to expression language in JSP 2.0 specification (which jsf-el 
uses) the value of exprA.exprB is the same as exprA[exprB]  and is 
evaluated like that:

.....
 if exprA is a List, coerce exprB to an int, if coercion failed, error.

I am in a situation where i have a Collection of items (List) which also 
has some proerties (like a name).
However, if i do "theBean.name" expression language tries to convert 
name to an int which fail and throws error, but what i want is in 
expression to reach "public String getName();" in the bean.

Does someone have a suggestion of expression to reach this property in 
my collection? Thanks.


Re: expression language and access of collection properties, howto

Posted by Cosma Colanicchia <co...@gmail.com>.
Sorry, you're right, the trick won't work with a List (it would if it
was a Map). Probably it would be more flexible to have single methods
(not doubled for Object,Object and Object,int), so all the properties
access strategy could be redefined in a custom PR.

A redesign surely will do it :) you could simply expose your List as a
bean property..

Bye
Cosma


2006/7/25, David Delbecq <de...@oma.be>:
> Thanks for your hint. Reading the specs it does not apply in my case,
> because propertyresolver methods are different based on the fact the
> object being accessed is a List/Array or another type of object. In my
> case, it is a List, so JSF will call the int version of
> propertyresolver, which will fail before entering resolver because it
> will first attempt to coerce the property name to an int.
> My only solution to keep with current design would be to use ELResolver,
> which is more flexible, but this is in JSP 2.1 specifications and  is
> used for j2EE 5.
> I think i'll better redesign my bean :)
>
> Thanks for your time,
> David Delbecq
> Cosma Colanicchia wrote:
> > I don't have any link at hands, but if you search on google you will
> > easily found some tutorial about implementing a custom property
> > resolver.
> >
> > Anyway, ProperyResolver are introduced by section 5 of JSF 1.1
> > Specifications.
> >
> >
> > Cosma
> >
> > 2006/7/24, David Delbecq <de...@oma.be>:
> >> I don't see in specification where it is stated this strategy is
> >> optional. Also, could you give me some reference on how to change the
> >> PropertyResolver used?
> >>
> >> Cosma Colanicchia wrote:
> >> > In JSF it's up to the property resolver to choose a strategy. The
> >> > default one, AFAIK, first check if it is a List or a Map.. only if
> >> > this condition isn't satisfied it tries to get the bean property.
> >> >
> >> > You could write a PropertyResolver decorator to handle things as you
> >> > need, for example checking the existence of a property even for the
> >> > Collections, before accessing its elements.
> >> >
> >> > Cosma
> >> >
> >> > 2006/7/24, David Delbecq <de...@oma.be>:
> >> >> Hello,
> >> >>
> >> >> according to expression language in JSP 2.0 specification (which
> >> jsf-el
> >> >> uses) the value of exprA.exprB is the same as exprA[exprB]  and is
> >> >> evaluated like that:
> >> >>
> >> >> .....
> >> >>  if exprA is a List, coerce exprB to an int, if coercion failed,
> >> error.
> >> >>
> >> >> I am in a situation where i have a Collection of items (List)
> >> which also
> >> >> has some proerties (like a name).
> >> >> However, if i do "theBean.name" expression language tries to convert
> >> >> name to an int which fail and throws error, but what i want is in
> >> >> expression to reach "public String getName();" in the bean.
> >> >>
> >> >> Does someone have a suggestion of expression to reach this
> >> property in
> >> >> my collection? Thanks.
> >> >>
> >> >>
> >>
> >>
>
>

Re: expression language and access of collection properties, howto

Posted by David Delbecq <de...@oma.be>.
Thanks for your hint. Reading the specs it does not apply in my case, 
because propertyresolver methods are different based on the fact the 
object being accessed is a List/Array or another type of object. In my 
case, it is a List, so JSF will call the int version of 
propertyresolver, which will fail before entering resolver because it 
will first attempt to coerce the property name to an int.
My only solution to keep with current design would be to use ELResolver, 
which is more flexible, but this is in JSP 2.1 specifications and  is 
used for j2EE 5.
I think i'll better redesign my bean :)

Thanks for your time,
David Delbecq
Cosma Colanicchia wrote:
> I don't have any link at hands, but if you search on google you will
> easily found some tutorial about implementing a custom property
> resolver.
>
> Anyway, ProperyResolver are introduced by section 5 of JSF 1.1 
> Specifications.
>
>
> Cosma
>
> 2006/7/24, David Delbecq <de...@oma.be>:
>> I don't see in specification where it is stated this strategy is
>> optional. Also, could you give me some reference on how to change the
>> PropertyResolver used?
>>
>> Cosma Colanicchia wrote:
>> > In JSF it's up to the property resolver to choose a strategy. The
>> > default one, AFAIK, first check if it is a List or a Map.. only if
>> > this condition isn't satisfied it tries to get the bean property.
>> >
>> > You could write a PropertyResolver decorator to handle things as you
>> > need, for example checking the existence of a property even for the
>> > Collections, before accessing its elements.
>> >
>> > Cosma
>> >
>> > 2006/7/24, David Delbecq <de...@oma.be>:
>> >> Hello,
>> >>
>> >> according to expression language in JSP 2.0 specification (which 
>> jsf-el
>> >> uses) the value of exprA.exprB is the same as exprA[exprB]  and is
>> >> evaluated like that:
>> >>
>> >> .....
>> >>  if exprA is a List, coerce exprB to an int, if coercion failed, 
>> error.
>> >>
>> >> I am in a situation where i have a Collection of items (List) 
>> which also
>> >> has some proerties (like a name).
>> >> However, if i do "theBean.name" expression language tries to convert
>> >> name to an int which fail and throws error, but what i want is in
>> >> expression to reach "public String getName();" in the bean.
>> >>
>> >> Does someone have a suggestion of expression to reach this 
>> property in
>> >> my collection? Thanks.
>> >>
>> >>
>>
>>


Re: expression language and access of collection properties, howto

Posted by Cosma Colanicchia <co...@gmail.com>.
I don't have any link at hands, but if you search on google you will
easily found some tutorial about implementing a custom property
resolver.

Anyway, ProperyResolver are introduced by section 5 of JSF 1.1 Specifications.


Cosma

2006/7/24, David Delbecq <de...@oma.be>:
> I don't see in specification where it is stated this strategy is
> optional. Also, could you give me some reference on how to change the
> PropertyResolver used?
>
> Cosma Colanicchia wrote:
> > In JSF it's up to the property resolver to choose a strategy. The
> > default one, AFAIK, first check if it is a List or a Map.. only if
> > this condition isn't satisfied it tries to get the bean property.
> >
> > You could write a PropertyResolver decorator to handle things as you
> > need, for example checking the existence of a property even for the
> > Collections, before accessing its elements.
> >
> > Cosma
> >
> > 2006/7/24, David Delbecq <de...@oma.be>:
> >> Hello,
> >>
> >> according to expression language in JSP 2.0 specification (which jsf-el
> >> uses) the value of exprA.exprB is the same as exprA[exprB]  and is
> >> evaluated like that:
> >>
> >> .....
> >>  if exprA is a List, coerce exprB to an int, if coercion failed, error.
> >>
> >> I am in a situation where i have a Collection of items (List) which also
> >> has some proerties (like a name).
> >> However, if i do "theBean.name" expression language tries to convert
> >> name to an int which fail and throws error, but what i want is in
> >> expression to reach "public String getName();" in the bean.
> >>
> >> Does someone have a suggestion of expression to reach this property in
> >> my collection? Thanks.
> >>
> >>
>
>

Re: expression language and access of collection properties, howto

Posted by David Delbecq <de...@oma.be>.
I don't see in specification where it is stated this strategy is 
optional. Also, could you give me some reference on how to change the 
PropertyResolver used?

Cosma Colanicchia wrote:
> In JSF it's up to the property resolver to choose a strategy. The
> default one, AFAIK, first check if it is a List or a Map.. only if
> this condition isn't satisfied it tries to get the bean property.
>
> You could write a PropertyResolver decorator to handle things as you
> need, for example checking the existence of a property even for the
> Collections, before accessing its elements.
>
> Cosma
>
> 2006/7/24, David Delbecq <de...@oma.be>:
>> Hello,
>>
>> according to expression language in JSP 2.0 specification (which jsf-el
>> uses) the value of exprA.exprB is the same as exprA[exprB]  and is
>> evaluated like that:
>>
>> .....
>>  if exprA is a List, coerce exprB to an int, if coercion failed, error.
>>
>> I am in a situation where i have a Collection of items (List) which also
>> has some proerties (like a name).
>> However, if i do "theBean.name" expression language tries to convert
>> name to an int which fail and throws error, but what i want is in
>> expression to reach "public String getName();" in the bean.
>>
>> Does someone have a suggestion of expression to reach this property in
>> my collection? Thanks.
>>
>>


Re: expression language and access of collection properties, howto

Posted by Cosma Colanicchia <co...@gmail.com>.
In JSF it's up to the property resolver to choose a strategy. The
default one, AFAIK, first check if it is a List or a Map.. only if
this condition isn't satisfied it tries to get the bean property.

You could write a PropertyResolver decorator to handle things as you
need, for example checking the existence of a property even for the
Collections, before accessing its elements.

Cosma

2006/7/24, David Delbecq <de...@oma.be>:
> Hello,
>
> according to expression language in JSP 2.0 specification (which jsf-el
> uses) the value of exprA.exprB is the same as exprA[exprB]  and is
> evaluated like that:
>
> .....
>  if exprA is a List, coerce exprB to an int, if coercion failed, error.
>
> I am in a situation where i have a Collection of items (List) which also
> has some proerties (like a name).
> However, if i do "theBean.name" expression language tries to convert
> name to an int which fail and throws error, but what i want is in
> expression to reach "public String getName();" in the bean.
>
> Does someone have a suggestion of expression to reach this property in
> my collection? Thanks.
>
>