On Fri, 2009-03-13 at 20:06 +0000, Johannes Ruthenberg wrote:
> Hi!
>
> I'm new to this list and to JSF in general. I have a problem with the
> t:selectItems component and would be grateful for any advice. I'm using
> MyFaces 1.2.5, Tomahawk 1.1.8 and Facelets.
>
> I have this in my file:
>
> <h:selectManyCheckbox id="selectedRoles" value="#{myBean.selectedRoles}"
> layout="pageDirection">
> <t:selectItems value="#{myBean.allRoles}" var="role"
> itemLabel="#{role}" itemValue="#{role}" />
> </h:selectManyCheckbox>
>
> selectedRoles is a Long[] array, allRoles is a Map<String, Long>,
> mapping the role name to their ID. What I want is the ID as value of the
> checkbox and the name as label text. Above code generates the ID as both
> the value and the label text though.
>
> Now page [1] has a more detailed explanation of the possibilities of the
> value attribute than [2], but I did check the source code of
> org.apache.myfaces.custom.selectitems.AbstractUISelectItems and it seems
> to be the same for both the JSF 1.1 and 1.2 version of the component.
>
> [1]
> http://myfaces.apache.org/tomahawk-project/tomahawk/tagdoc/t_selectItems.html
> [2]
> http://myfaces.apache.org/tomahawk-project/tomahawk12/tagdoc/t_selectItems.html
>
> The documentation under [1] says:
>
> value: An EL expression that specifies the contents of the selection
> list. The expression can refer to one of the following:
>
> 1. A single SelectItem
> 2. An array or Collection of SelectItem instances
> 3. A Map. The contents of the Map are used to create SelectItem
> instances, where the SelectItem's label is the map's key value, and the
> SelectItem's value is the map's value. When using a map, it is
> recommended that an ordered implementation such as java.util.TreeMap is
> used.
>
> Number 3 is exactly what I want, I'm even using a TreeMap. I would
> expect to get the keys as labels and the values as checkbox values
> automatically with just using <t:selectItems
> value="#{myBean.allRoles}"/>. But looking in the source code, I don't
> see anything to provide this functionality. Unfortunately I also don't
> see a way to configure the component with the other attributes to do
> this, since only the value of the Map.Entry is set as request attribute.
> Meaning, I can't just do something like:
>
> <t:selectItems value="#{myBean.allRoles}" var="mapEntry"
> itemLabel="#{mapEntry.key}" itemValue="#{mapEntry.value}" />
>
> So, am I missing something here? Is there a way to do this? Or is the
> documentation simply wrong?
Have you tried this?
<t:selectItems value="#{myBean.allRoles}"/>
Regards,
Simon