1

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 ?

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498

1 Answers1

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • when i tried that no checkboxes appears at all, do i have to include form name before the id ? – Mahmoud Saleh Dec 14 '11 at 12:39
  • 1
    Just to test, what if you specify the checkboxes individually with a fixed ID? Like so `` etc. If that works, then try `` instead of ``, only with a `List` instead of `Map` if you aren't on JSF 2.1 yet. – BalusC Dec 14 '11 at 13:03
  • fixed id works fine, but ui:repeat doesn't work either, strange! any ideas ? – Mahmoud Saleh Dec 14 '11 at 13:16
  • well, after debugging i found that i was doing something wrong, i was initializing the map in the prerenderView method while the map is getting accessed by the foreach before that phase, don't fully understand why, but it works fine now. – Mahmoud Saleh Dec 14 '11 at 14:05
  • but is there's a way to make the label of the checkbox dynamic based on a condition to make the label bold or not ? – Mahmoud Saleh Dec 14 '11 at 14:07
  • Just use ``. – BalusC Dec 14 '11 at 14:08
  • As to the map initializing, the `` is a view build time tag, not a view render time tag like ``. So you need to initialize in (post)constructor instead, or to replace it by ``. – BalusC Dec 14 '11 at 14:12
  • one more question, i wanted to add after the checkbox a conditional image, and conditional style for the label, what the above code generates is the `image > bold text > checkbox > checkbox text`, while i though that this will generate only: `image > bold text > checkbox` please advise how to accomplish that – Mahmoud Saleh Dec 14 '11 at 14:20
  • Remove the labels from `` value. – BalusC Dec 14 '11 at 14:23
  • Just don't supply item labels. E.g. `itemLabel=""`. – BalusC Dec 14 '11 at 14:30
  • well, i tried the following but still displaying the label after the checkbox: `` – Mahmoud Saleh Dec 14 '11 at 14:37
  • tried the following, but doesn't work too: `` – Mahmoud Saleh Dec 14 '11 at 14:53
  • No? Sorry, then I don't know it. Ask a new question. It's perhaps related to ICEfaces. – BalusC Dec 14 '11 at 14:54
  • another question is asked, but any ideas how to display the list in the above code in vertical not horizontal i mean to be equivalent to pageDirection layout ? – Mahmoud Saleh Dec 14 '11 at 15:15
  • Wrap them in `
    `.
    – BalusC Dec 14 '11 at 15:19