I’m using Richfaces JSF and I want to iterate over an Map<Object,Object>. I see many examples on Sun forums and other sites but in my case it doesn’t work. Here is my XHTML code:
<c:forEach items="#{order.customOptions}" var="option">
<h:outputText value="this text does not print" />
<h:outputText value="#{option.value.name}" />
<h:outputText value="#{option.value.key}" />
</c:forEach>
The “order” object is of type Order. The “customOptios” is of type Map<CustomOption,CustomOptionValue>. When I create an Javascript alert on to print ‘#{order.customeOptions}’ its content is correct, but it does not even enter in c:forEach loop.
Update 1:: I tried a list but it doesn’t work. I used list and got answer in other pages. I also use a4j:poll and some other ajax component is there any problem with them?
<c:forEach items="#{order.food.cusomableOptions}" var="option">
<h:outputText value="this text does not print" />
<h:outputText value="#{option.title}" />
</c:forEach>
Update 2: Here is output of <h:outputText value="#{order.customOptions}" />:
{model.CustomOption@be8464=model.CustomOptionValue@14e8ac9,
model.CustomOption@1ea0c8b=model.CustomOptionValue@78f4,
model.CustomOption@24389c=model.CustomOptionValue@3f0bc0,
model.CustomOption@a765c=model.CustomOptionValue@3b34ca,
model.CustomOption@95868c=model.CustomOptionValue@199de59}
Update 3: when I use it outside of rich:column it works,
but when I use it in a rich:dataTable and rich:column tag it doesn’t work:
<rich:column>
<f:facet name="header">
<h:outputText value="xf" />
</f:facet>
<c:forEach items="#{order.customOptions}" var="option">
<p><h:outputText value="option : #{option.key.title}" /></p>
</c:forEach>
</rich:column>
JSTL and JSF doesn’t work seamlessly together in sync as you would intuitively expect from the ordering in the source code. Roughly said, JSTL processes the entire page from top to bottom first and then hands the generated output (thus, without any JSTL tags, but with its generated output) over to JSF which in turn processes the entire page from top to bottom again.
JSF
UIDatacomponents likeh:dataTableandrich:dataTablehaven’t generated any rows yet at the moment JSTL runs, which cauces that you won’t see anything fromc:forEachinside a column.To fix this, you should rather use the JSF-supplied iterating components, such as RichFaces’
a4j:repeat, or Facelets’ui:repeat, or Tomahawk’st:dataList. They all do less or more the same as the JSTLc:forEach.For the remnant of JSTL tags, only the functions taglib is useful in JSF, all the other taglibs are superflous in a JSF environment since it either provides the same functionality out of the box (JSTL core and format taglibs), or it simply doesn’t suit in the MVC ideology (JSTL sql and xml taglibs).