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

泪湿孤枕 提交于 2019-11-27 16:29:10

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