Search code examples
jsfjakarta-eejsf-2icefacesicefaces-2

Custom selectItems


i want to customize selectItems to display an image conditionally beside each checkbox so first i tried to display the image for all checkboxes but it gets displayed only once, here's what i tried:

<h:selectManyCheckbox value="#{myBean.checkboxesArry}" layout="pageDirection">

              <f:selectItems value="#{myBean.mapOfCheckBoxes}" var="entry">                            
                <label>           
                <ice:graphicImage url="/resources/images/myImage.bmp"/>            
                <b>#{entry.value}</b>           
                </label>
              </f:selectItems>

            </h:selectManyCheckbox>

please advise how to accomplish that ?


Solution

  • You cannot nest UI compnents in <f:selectItems> that way. I however see that you're using ICEfaces, you should then be able to use <ice:selectManyCheckbox layout="spread"> in combination with <ice:checkbox> instead.

    <ice:selectManyCheckbox id="foo" value="#{myBean.checkboxesArry}" layout="spread">
        <f:selectItems value="#{myBean.mapOfCheckBoxes}" />
    </ice:selectManyCheckbox>
    
    <c:forEach items="#{myBean.mapOfCheckBoxes}" var="entry" varStatus="loop">
        <ice:checkbox for="foo" index="#{loop.index}" />
        <ice:graphicImage url="/resources/images/myImage.bmp" />
        <b>#{entry.value}</b>
    </c:forEach>
    

    (untested as I don't use ICEfaces, but the above construct works for Tomahawk, from which ICEfaces has basically copied the implementation; you can also use <ui:repeat> but it only supports Map since JSF 2.1)

    See also: