Collection of selectManyCheckbox inside a ui:repeat knows which element of the repeater it belongs to

Simplest way would be to just bind the value of the checkbox group to the currently iterated object instead of all checkbox groups to one and same parent bean property.

In code, just replace

value="#{gridPopUpBean.oneQuestionUserAnswerList}"

by

value="#{p.oneQuestionUserAnswerList}"

and make changes in the model accordingly.

Alternatively, you can also provide a Map of all answers by question ID in the parent bean. Here’s a kickoff example which uses more self-documenting variable names than you have, so that it’s better understandable:

<ui:repeat value="#{bean.questions}" var="question">
    ...
    <h:selectManyCheckbox value="#{bean.answers[question.id]}">
        <f:selectItems value="#{question.answers}" />
    </h:selectManyCheckbox>
    ...
</ui:repeat>

with e.g.

private Map<Long, Answer[]> answers = new HashMap<Long, Answer[]>();

Leave a Comment