Custom selectItems

有些话、适合烂在心里 提交于 2019-12-24 08:58:42

问题


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 ?


回答1:


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:

  • Radio buttons in different parts of the page


来源:https://stackoverflow.com/questions/8501810/custom-selectitems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!