views:

1121

answers:

1

While using <c:forEach> the items values is not substituted properly. If i use <a4j:repeat> or <ui:repeat> instead of <c:forEach> inside a <rich:dataTable>, radio button is not rendering properly. I also found reason for this in http://community.jboss.org/wiki/Cantusea4jrepeattoiteratethemenuItemstabsetc

How do I resolve this issue?

<f:selectItems> is working inside but i want to send a choice type to server

  <rich:dataTable var="answer" value="#{answers}">
    <rich:column>
      <f:selectOneRadio value="#{response.value}">
        <c:forEach items="#{answer.choices}" var="choice">
            <f:selectItem itemLabel="#{choice.value}" itemValue="#{choice.type}"/>
        </c:forEach>
     </f:selectOneRadio>
   </rich:column>
  </rich:dataTable>
+3  A: 

If you're already on JSF 2.x, then you can just use the following construct:

<f:selectItems value="#{answer.choices}" var="choice" itemValue="#{choice.type}" itemLabel="#{choice.value}" />

If you're still on JSF 1.x, then best is to use f:selectItems in combination with the following logic in the constructor of answer bean to prepopulate it:

this.selectItems = new ArrayList<SelectItem>();
for (Choice choice : this.choices) {
    selectItems.add(new SelectItem(choice.getType(), choice.getValue()));
}

so that you can end up with

<f:selectItems value="#{answer.selectItems}" />
BalusC
We are still on JSF 1.x (RichFaces 3.3.2.SR1) and don't have plans to move to JSF 2.x as of now. Will try your suggestion shortly
Kalpana
Have a moment, I now see that you tagged Seam as well. You should take a look for Seam's `s:selectItems` as well, it provides similar construct as the JSF 2.x `f:selectItems`.
BalusC
Based on your suggestion, i tried the following.I have the "correct" variable in my "answerList" bean in that I tried to store the selected value, but the radio button always returns a null value.private String correct;<h:selectOneRadio value="#{answerList.correct}"> <f:selectItems value="#{answer.selectItems}" /></h:selectOneRadio>Also while inspecting using FireBug element radio button labels and values are found to be correct.Not sure, what I am missing here
Kalpana
What does `h:message` or `h:messages` say? `Value not valid`? If so, you need to preserve the very same list on the subsequent request. Thus, prepopulate it in bean constructor or `@PostConstruct`. Or abuse the session scope.
BalusC