myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From EDHEDH <>
Subject Re: t:selectItems with a map
Date Sun, 04 Apr 2010 16:03:46 GMT

I'm replying because I have a related problem. Hope somebody can help.

I'm using the following code (it's part of a for each loop in which a vary
the unDimDefSid variable).

<ice:selectOneListbox id="#{unDimDefSid}"
value="#{addBinDimRelActionBean.mapOfUnDimSelectItems[unDimDefSid]}" />

The listboxes are displayed correctly with the values from the appropriate
map entry determined by the value of the unDimDefSid variable. That is, the
f:selectItems is working appropriately.

However the expression in the value= attribute doesn't work as expected.
On submitting the form (commandbutton) I would have expected the selected
value to be added to the map at the specified (value of unDimDefSid
variable) key.  
However I get a jsf el propertynotfoundexception, target unreachable,
exception instead.

Is it impossible to put the selected value of a listbox to specific map
position ?
If not, how should it be done ?
If I have many listboxes that are created as above in the same for each
loop. Can they all write to the same back map (at a different key) ?

The reason behind all this I have an unknown number of listboxes to display.
That is, the number of listboxes and the values they contain is determined
at runtime.

Any advice is welcome.


Johannes Ruthenberg-2 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] 
> [2] 
> 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?
> Regards,
> Johannes Ruthenberg

View this message in context:
Sent from the MyFaces - Users mailing list archive at

View raw message