You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Kevin Hale Boyes <kc...@gmail.com> on 2005/11/05 00:48:06 UTC

collection size

I have a handler return a list of SelectItems that I use as:

<h:selectOneMenu  ...>
    <f:selectItems value="#{handler.types}"/>
   ...


But, if there is only one item in the list then I'd like to change it
to plain output text (and a hidden input)

So, I tried

<h:panelGroup rendered="#{length(handler.types) > 1}">
    <h:selectOneMenu  ...>
</h:panelGroup>
<h:panelGroup rendered="#{length(handler.types) == 1}">
    <h:inputHidden rendered="true" ...
</h:panelGroup>


but that isn't valid expression syntax.

How do I get the size of my collection (List)?

Thanks,
Kevin.

Re: collection size

Posted by Mike Kienenberger <mk...@gmail.com>.
Actually, you can use functions in jsf el.   It's just difficult to
install functions under the MyFaces EL implementation.

Using facelets or JSF RI makes it far easier (and supports
jstl:length, which is what you want, just by setting up a namespace
reference).

For example, using MyFaces and Facelets, I can do this:

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

    <h:commandButton rendered="#{1 !=
jstl:length(equipmentCategory.activityTypeList)}" ...
======================

If you need to do this in "pure" MyFaces, then see this thread.   This
shows how I used to do this before I switched over to using Facelets
as my ViewHandler.

http://www.archivum.info/dev@myfaces.apache.org/2005-07/msg00390.html

-Mike


On 11/5/05, Mathias Brökelmann <mb...@googlemail.com> wrote:
> unfortunately you can not use functions in jsf el expressions.
> try to create a new method in your handler which determines if the
> list contains only one element.
>
> 2005/11/5, Kevin Hale Boyes <kc...@gmail.com>:
> > I have a handler return a list of SelectItems that I use as:
> >
> > <h:selectOneMenu  ...>
> >     <f:selectItems value="#{handler.types}"/>
> >    ...
> >
> >
> > But, if there is only one item in the list then I'd like to change it
> > to plain output text (and a hidden input)
> >
> > So, I tried
> >
> > <h:panelGroup rendered="#{length(handler.types) > 1}">
> >     <h:selectOneMenu  ...>
> > </h:panelGroup>
> > <h:panelGroup rendered="#{length(handler.types) == 1}">
> >     <h:inputHidden rendered="true" ...
> > </h:panelGroup>
> >
> >
> > but that isn't valid expression syntax.
> >
> > How do I get the size of my collection (List)?
> >
> > Thanks,
> > Kevin.
> >
>
>
> --
> Mathias
>

Re: collection size

Posted by Mathias Brökelmann <mb...@googlemail.com>.
unfortunately you can not use functions in jsf el expressions.
try to create a new method in your handler which determines if the
list contains only one element.

2005/11/5, Kevin Hale Boyes <kc...@gmail.com>:
> I have a handler return a list of SelectItems that I use as:
>
> <h:selectOneMenu  ...>
>     <f:selectItems value="#{handler.types}"/>
>    ...
>
>
> But, if there is only one item in the list then I'd like to change it
> to plain output text (and a hidden input)
>
> So, I tried
>
> <h:panelGroup rendered="#{length(handler.types) > 1}">
>     <h:selectOneMenu  ...>
> </h:panelGroup>
> <h:panelGroup rendered="#{length(handler.types) == 1}">
>     <h:inputHidden rendered="true" ...
> </h:panelGroup>
>
>
> but that isn't valid expression syntax.
>
> How do I get the size of my collection (List)?
>
> Thanks,
> Kevin.
>


--
Mathias