myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Korherr <jakob.korh...@gmail.com>
Subject Re: t:selectItems with a map
Date Tue, 06 Apr 2010 09:43:32 GMT
Hi Edwin,

I am pretty sure your problem exists, because you are using the for each
loop. You see, when JSF renders the page unDimDefSid is set in the request
scope for every loop and thus JSF is able to get the right value from the
ValueExpression, because both addBinDimRelActionBean.mapOfUnDimSelectItems
and unDimDefSid can be resolved.

However when setting the value I think the problem is that unDimDefSid
cannot be resolved (but frankly I don't know if this is a JSF bug/problem)
and so JSF cannot set the value, because basically setting the value in a
Map is possible.

Have you tried using a t:dataTable to render the input fields instead of the
for each loop?

Regards,
Jakob

2010/4/4 EDHEDH <edwin.dhondt@hp.com>

>
> 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.mapOfSelectedUnDims[unDimDefSid]}">
>  <f:selectItems
> value="#{addBinDimRelActionBean.mapOfUnDimSelectItems[unDimDefSid]}" />
> </ice:selectOneListbox>
>
> 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.
>
> Thanks,
> EDH
>
>
> 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]
> >
> 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?
> >
> > Regards,
> > Johannes Ruthenberg
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/t%3AselectItems-with-a-map-tp22504143p28133463.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message