Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF h:selectManyCheckbox inside ui:repeat via Map entry
    text
    copied!<p>I faced with problem, when I put value as <code>String</code> into <code>List&lt;String&gt;</code> inside <code>&lt;ui:repeat&gt;</code> when I press button I see that <code>List&lt;String&gt;</code> contains just records for last element of ui:repeat.</p> <pre><code>&lt;ui:repeat value="#{util:toList(test.mapQestionsWithAnswers)}" var="entry"&gt; &lt;h:inputHidden value="#{entry.key.questionId}" /&gt; &lt;h:outputText value="#{entry.key.question}" rendered="#{not empty entry.value}" /&gt; &lt;p:selectManyCheckbox value="#{test.questionAnswerList}" layout="pageDirection"&gt; &lt;f:selectItems value="#{entry.value}" var="ans" itemValue="#{entry.key.questionId} #{ans.answer.answerId}" itemLabel="${ans.answer.answer}" /&gt; &lt;/p:selectManyCheckbox&gt; &lt;/ui:repeat&gt; </code></pre> <p>Idea with <code>util:toList</code> from Baluscanswer <a href="https://stackoverflow.com/questions/6001743/how-to-show-hashmap-values-in-jsf">How to show hashmap values in jsf?</a></p> <p><strong>//UPDATED</strong> I rewrite this code without using map</p> <pre><code>&lt;ui:repeat value="${test.questionList}" var="question"&gt; &lt;h:outputText value="#{question.question}" rendered="#{not empty question}" /&gt; &lt;p:selectManyCheckbox value="#{test.questionAnswerList}" layout="pageDirection"&gt; &lt;f:selectItems value="#{question.questionAnswers}" var="ans" itemValue="#{ans.questionAnswerIdentifer.questionId} #{ans.questionAnswerIdentifer.answerId}" itemLabel="#{ans.answer.answer}" /&gt; &lt;/p:selectManyCheckbox&gt; &lt;/ui:repeat&gt; </code></pre> <p>But it doesn't help me I can get in <code>List&lt;String&gt;</code> just pairs question answer for last question in <code>&lt;ui:repeat/&gt;</code>. Seems as after every iteration questionAnswerList become empty</p> <p>//Ok I read some article <a href="https://stackoverflow.com/questions/13147440/primefaces-manycheckbox-inside-uirepeat-calls-setter-method-only-for-last-loop">Primefaces ManyCheckbox inside ui:repeat calls setter method only for last loop</a></p> <p>And I decide use map Map></p> <p>But in this part error <code>ClassCastException</code> String cannot be cast to List</p> <pre><code>public List&lt;String&gt; getQuestionAnswerList() { // return questionAnswerList; List&lt;String&gt; selectedQuestionAnswer = new ArrayList&lt;String&gt;(); if (!selectedItems.isEmpty()) { Set&lt;Long&gt; idsSet = selectedItems.keySet(); for(Long questionId : idsSet){ List&lt;String&gt; questionAnswerPair = selectedItems.get(questionId); selectedQuestionAnswer.addAll(questionAnswerPair); } } return selectedQuestionAnswer; } &lt;p:selectManyCheckbox value="#{test.selectedItems[question.questionId]}" layout="pageDirection"&gt; &lt;f:selectItems value="#{question.questionAnswers}" var="ans" itemValue="#{ans.questionAnswerIdentifer.questionId} #{ans.questionAnswerIdentifer.answerId}" itemLabel="#{ans.answer.answer}" /&gt; &lt;/p:selectManyCheckbox&gt; </code></pre> <p>How I can get all choosen values in <code>List&lt;String&gt;</code>?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload