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/12/19 11:45:54 UTC

Accessing array or collection size in JSF expresison language

Hello,

i'd like, in jsf to print a statement like this:

You have #{someBean.someArray.size} item(s) just before a facelets
c:forEach.

example:
You have 28 item(s): item1, item2, item3, ...  (get full list of items)

While i can do the partial iteration without problem, i am wondering how
to the array size (Or in more general, any collection size)
I'd like to avoid creation of a method someBean.getSomeArraySize() as
it's seems to me it's like doing double work (getSommeArray returns and
array and getSommeArray returns information present in Array)

Re: Accessing array or collection size in JSF expresison language

Posted by Mike Kienenberger <mk...@gmail.com>.
In Facelets, you can use the jstl:length() function -- you don't have
to create your own function.

	  xmlns:jstl="http://java.sun.com/jsp/jstl/functions"

                        rendered="#{jstl:length(list) gt 0 and
page.limit eq jstl:length(list)}"

Note that you can also use "#{empty list}" for comparing for 0 items
-- just discovered this recently.


On 12/19/06, David Delbecq <de...@oma.be> wrote:
> Hello,
>
> i'd like, in jsf to print a statement like this:
>
> You have #{someBean.someArray.size} item(s) just before a facelets
> c:forEach.
>
> example:
> You have 28 item(s): item1, item2, item3, ...  (get full list of items)
>
> While i can do the partial iteration without problem, i am wondering how
> to the array size (Or in more general, any collection size)
> I'd like to avoid creation of a method someBean.getSomeArraySize() as
> it's seems to me it's like doing double work (getSommeArray returns and
> array and getSommeArray returns information present in Array)
>

Re: Accessing array or collection size in JSF expresison language

Posted by David Delbecq <de...@oma.be>.
Thanks, i'll give it a try. Forgot how easy it was to create custom
function with facelets

En l'instant précis du 12/19/06 16:35, David Chandler s'exprimait dans
toute sa noblesse:
> In facelets, you can create an EL function to do this.
>
> See
> https://facelets.dev.java.net/nonav/docs/dev/docbook.html#taglib-function
>
> /dmc
>
> On 12/19/06, David Delbecq <de...@oma.be> wrote:
>> Hello,
>>
>> i'd like, in jsf to print a statement like this:
>>
>> You have #{someBean.someArray.size} item(s) just before a facelets
>> c:forEach.
>>
>> example:
>> You have 28 item(s): item1, item2, item3, ...  (get full list of items)
>>
>> While i can do the partial iteration without problem, i am wondering how
>> to the array size (Or in more general, any collection size)
>> I'd like to avoid creation of a method someBean.getSomeArraySize() as
>> it's seems to me it's like doing double work (getSommeArray returns and
>> array and getSommeArray returns information present in Array)
>>
>
>


Re: Accessing array or collection size in JSF expresison language

Posted by David Chandler <da...@learnjsf.com>.
In facelets, you can create an EL function to do this.

See https://facelets.dev.java.net/nonav/docs/dev/docbook.html#taglib-function

/dmc

On 12/19/06, David Delbecq <de...@oma.be> wrote:
> Hello,
>
> i'd like, in jsf to print a statement like this:
>
> You have #{someBean.someArray.size} item(s) just before a facelets
> c:forEach.
>
> example:
> You have 28 item(s): item1, item2, item3, ...  (get full list of items)
>
> While i can do the partial iteration without problem, i am wondering how
> to the array size (Or in more general, any collection size)
> I'd like to avoid creation of a method someBean.getSomeArraySize() as
> it's seems to me it's like doing double work (getSommeArray returns and
> array and getSommeArray returns information present in Array)
>


-- 
David Chandler
Development Coach
learnjsf.com