我遇到了问题,当我按下按钮时将值String
放入List<String>
内部<ui:repeat>
时,我看到它只List<String>
包含 ui:repeat 的最后一个元素的记录。
<ui:repeat value="#{util:toList(test.mapQestionsWithAnswers)}" var="entry">
<h:inputHidden value="#{entry.key.questionId}" />
<h:outputText value="#{entry.key.question}"
rendered="#{not empty entry.value}" />
<p:selectManyCheckbox value="#{test.questionAnswerList}"
layout="pageDirection">
<f:selectItems value="#{entry.value}" var="ans"
itemValue="#{entry.key.questionId} #{ans.answer.answerId}"
itemLabel="${ans.answer.answer}" />
</p:selectManyCheckbox>
</ui:repeat>
util:toList
来自 Baluscanswer 的想法如何在 jsf 中显示 hashmap 值?
//更新 我重写这段代码而不使用地图
<ui:repeat value="${test.questionList}" var="question">
<h:outputText value="#{question.question}"
rendered="#{not empty question}" />
<p:selectManyCheckbox value="#{test.questionAnswerList}"
layout="pageDirection">
<f:selectItems value="#{question.questionAnswers}" var="ans"
itemValue="#{ans.questionAnswerIdentifer.questionId} #{ans.questionAnswerIdentifer.answerId}"
itemLabel="#{ans.answer.answer}" />
</p:selectManyCheckbox>
</ui:repeat>
但这对我没有帮助,我只能List<String>
在<ui:repeat/>
. 似乎在每次迭代之后 questionAnswerList 都变空了
//好吧,我读了一些文章Primefaces ManyCheckbox inside ui:repeat calls setter method only for last loop
我决定使用地图 Map>
但是在这部分错误ClassCastException
字符串不能转换为列表
public List<String> getQuestionAnswerList() {
// return questionAnswerList;
List<String> selectedQuestionAnswer = new ArrayList<String>();
if (!selectedItems.isEmpty()) {
Set<Long> idsSet = selectedItems.keySet();
for(Long questionId : idsSet){
List<String> questionAnswerPair = selectedItems.get(questionId);
selectedQuestionAnswer.addAll(questionAnswerPair);
}
}
return selectedQuestionAnswer;
}
<p:selectManyCheckbox value="#{test.selectedItems[question.questionId]}"
layout="pageDirection">
<f:selectItems value="#{question.questionAnswers}" var="ans"
itemValue="#{ans.questionAnswerIdentifer.questionId} #{ans.questionAnswerIdentifer.answerId}"
itemLabel="#{ans.answer.answer}" />
</p:selectManyCheckbox>
我怎样才能得到所有选择的值List<String>
?