Reputation: 33625
i want to use the JSTL function contains in JSF2 here's what i tried but the condition always evaluates to false, i think i am missing something:
<c:forEach items="#{myBean.toSendCheckBoxes}" var="entry" varStatus="loop">
<input type="checkbox" name="myArray" value="#{entry.value}" />
<c:choose>
<c:when test="#{fn:contains(entry.key,'g')}">
<ice:graphicImage url="/resources/images/image1.bmp" />
<b>#{entry.key}</b>
</c:when>
<c:otherwise>
<ice:graphicImage url="/resources/images/image2.bmp" />
<span>#{entry.key}</span>
</c:otherwise>
</c:choose>
</c:forEach>
if there's another JSF way to accomplish that, would be very nice to mention it, thanks in advance.
Upvotes: 2
Views: 2248
Reputation: 2121
I use t:dataList
(myfaces tomahawk xmlns:t="http://myfaces.apache.org/tomahawk"
) for looping over elements to have correct identifier generation and rendered
attribute for different displaying of elements in the list.
<t:dataList layout="simple" value="#{myBean.toSendCheckBoxes}" var="entry">
<input type="checkbox" name="myArray" value="#{entry.value}" />
<h:panelGroup rendered="#{fn:contains(entry.key,'g')}">
<ice:graphicImage url="/resources/images/image1.bmp" />
<b>#{entry.key}</b>
</h:panelGroup>
<h:panelGroup rendered="#{not fn:contains(entry.key,'g')}">
<ice:graphicImage url="/resources/images/image2.bmp" />
<span>#{entry.key}</span>
</h:panelGroup>
</t:dataList>
I've had issues with dynamic element rendering (show/hide rows) within ui:repeat
, so I had to use t:dataList
instead.
Upvotes: 1
Reputation: 12880
More JSFish way to do it would be
<ui:repeat value="#{myBean.toSendCheckBoxes}" var="entry" varStatus="loop">
<input type="checkbox" name="myArray" value="#{entry.value}" />
<ui:fragment rendered="#{fn:contains(entry.key,'g')}">
<ice:graphicImage url="/resources/images/image1.bmp" />
<b>#{entry.key}</b>
</ui:fragment>
<ui:fragment rendered="#{!fn:contains(entry.key,'g')}">
<ice:graphicImage url="/resources/images/image2.bmp" />
<span>#{entry.key}</span>
</ui:fragment>
</ui:repeat>
or even
<ui:repeat value="#{myBean.toSendCheckBoxes}" var="entry" varStatus="loop">
<input type="checkbox" name="myArray" value="#{entry.value}" />
<ice:graphicImage url="#{fn:contains(entry.key,'g') ? '/resources/images/image1.bmp' : '/resources/images/image2.bmp'}" />
<span class="#{fn:contains(entry.key,'g') ? 'bold-style' : ''}">#{entry.key}</span>
</ui:repeat>
but I would expect your condition to evaluate properly nevertheless.
Upvotes: 3