jsfselectoneradio

JSF multiple groups of selectOneRadio on a page: how to recover the values?


I have a jsf page with multiple radiobutton groups (dynamically generated) on it. I need to retrieve the values from it in a backing bean, but fails to do so.

The business: a user wants to subscribe to a course that consists of multiple groups of coursedays. The user can choose the coursedays. So if a course consists of for example 4 coursedays, organised in 3 different groups, the user can choose from 12 coursedays, in blocks of 3.

The relevant part of the xhtml-page:

<c:forEach var="cd1" items="#{coursedayBean.getCoursedays(groupBean.getFirstGroup}">
  <h:selectOneRadio value="#{subscriptionBean.selectedCoursedays[cd1.sequenceNr]}" >
    <f:selectItems value="#{coursedayBean.getCoursedaysSelectItems}"/>
  </h:selectOneRadio>
</c:forEach>

This results in a n*m matrix of radiobuttons where I want to retrieve n values. The selectItems are of type <Long, String>.

In my backing bean, I declared the following:

public List<String> getSelectedCoursedays() {
  return selectedCoursedays;
}

public void setSelectedCoursedays(List<String> selectedCoursedays) {
  this.selectedCoursedays = selectedCoursedays;
}

I tried with a Map, List, but none of them worked. The setSelectedCoursedays is never called. How do I declare the array/list/map to get the values in my backing bean?

#{subscriptionBean.selectedCoursedays[cd1.sequenceNr]}

doesn't do the trick.


Solution

  • It is miss understanding between c:forEach and ui:repeat. c:forEach will not build UI component tree nodes. Firstly, you have to reference difference between them here.