-
1. Re: Map iteration over the set of entries in the view?
gavin.king Feb 16, 2008 4:11 AM (in response to dam)#{aMap.entrySet} should work.
-
2. Re: Map iteration over the set of entries in the view?
dam Feb 16, 2008 10:21 AM (in response to dam)Shouldn't it be possible to get the key out in the following way?
ui:repeat value="#{aMap.entrySet}" var="entry"> <h:outputText value="#{entry.key}" /> </ui:repeat>
I got this error
Exception during request processing: Caused by javax.faces.FacesException with message: "Problem in renderResponse: javax.el.PropertyNotFoundException: /layout/menu_right.xhtml @43,42 value="#{entry.key}": Property 'key' not found on type java.util.HashMap$EntrySet"
-
3. Re: Map iteration over the set of entries in the view?
gavin.king Feb 16, 2008 11:47 AM (in response to dam)OK, my bad, I forgot UIRepeat is extending UIData. The problem is that UIData doesn't know how to iterate Sets in JSF 1.x. So you need to transform the entrySet into a List.
-
4. Re: Map iteration over the set of entries in the view?
dam Feb 16, 2008 12:26 PM (in response to dam)Thanks, that gives sense to the failure. However, it seems insufficient that the UIRepeat can't iterate over a set. Is there another possibility besides having a supporting list for the map?
-
5. Re: Map iteration over the set of entries in the view?
gavin.king Feb 16, 2008 4:49 PM (in response to dam)Oh, it is definitely insufficient. But this needs to be fixed in JSF, we have no control over that. If it bothers you, you could write an EL function like my:toList(set) that converts sets to lists.
-
6. Re: Map iteration over the set of entries in the view?
andrey.chorniy Feb 17, 2008 7:13 PM (in response to dam)Here is the article about writing such convert-function
http://sfjsf.blogspot.com/2006/03/usings-sets-with-uidata.htmlusage example:
<h:dataTable value="#{makeList.list[mySet]}">
-
7. Re: Map iteration over the set of entries in the view?
pizzi Mar 26, 2008 4:42 PM (in response to dam)<ui:repeat value="#{aMap.keySet().toArray()}" var="mapEntry"> <h:outputText value="#{mapEntry.key} #{mapEntry.value}" /> </ui:repeat>
bye ;)
--pizzi
-
8. Re: Map iteration over the set of entries in the view?
skanky78 Mar 26, 2008 10:20 PM (in response to dam)No, that doesn't work because the var
mapEntry
is only a key in your example. But you could use the key to get the corresponding value via#{aMap[key]}
.cheers,
sven -
9. Re: Map iteration over the set of entries in the view?
cleverswine Mar 31, 2008 10:52 PM (in response to dam)The wiki sample application does this. BlogDirectory.java contains:
// Need to expose this as a datamodel so Seam can convert our map to a collection of Map.Entry objects @DataModel private Map<Date, List<BlogEntry>> recentBlogEntries;
which is then used in plugin.xhtml (2.0.1) and index.html (trunk)
<h:dataTable value="#{blog.recentBlogEntries}" var="blogEntry" rows="3"> <h:column> <div class="blogEntry"> <h3>#{blogEntry.title}</h3> <!-- why isn't this #{blogEntry.value.title| ?? -->
but Map<String, String> does not work in my app using Seam 2.0.1. What's wrong?
<h:dataTable value="#{manager.properties}" var="mapEnty"> <h:column> <f:facet name="header">key</f:facet> <h:outputText value="#{mapEnty.key}"/> </h:column> <h:column> <f:facet name="header">value</f:facet> <h:inputText value="#{mapEnty.value}"/> </h:column> </h:dataTable>
-
10. Re: Map iteration over the set of entries in the view?
benmoore Apr 1, 2008 7:48 PM (in response to dam)See my post about this here.
-
11. Re: Map iteration over the set of entries in the view?
umer Feb 22, 2011 2:04 AM (in response to dam)that's great..
<ui:repeat var="mapEntry" value="#{webUserBean.map.entrySet().toArray()}" varStatus="current"> <h:outputText value=" #{mapEntry.key} #{mapEntry.value}" /> </ui:repeat>