0

My xhtml file contains the code where someMB.allQuestions returns a list of object of Questions class.

<c:forEach items="#{someMB.allQuestions}" var="question">    
    <h:outputText value="#{question.name}" />
    <h:selectBooleanCheckbox value="#{myBean.isChecked}">
        <f:ajax listener="#{myBean.addQuestion(question)}"  />
    </h:selectBooleanCheckbox>

 </c:forEach>

My Bean code is:

private boolean isChecked;
HashSet<Questions> totalQuestions = new HashSet<>();
// getter setter
public string addQuestion(Questions questions){
    if(isChecked){
        totalQuestions.add(questions);
    }

}

Here addQuestion() method is not called. but if I remove the parameter and call the method without argument then it works. I don't know why. Can anybody give me a solution about calling with parameter.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Mamunur Rimon
  • 65
  • 1
  • 8
  • Helpful? http://stackoverflow.com/questions/17983378/pcommandbutton-not-working-inside-cforeach or http://stackoverflow.com/questions/20262945/passing-argument-to-actionlistener-method-with-pcommandlink-inside-cforeach-lo – Kukeltje Apr 12 '16 at 06:53
  • Not helpful. I wanted to call a method on clicking a checkbox not command button or command link. – Mamunur Rimon Apr 12 '16 at 07:43
  • I know you want to use a different component, but the underlying problem/cause is most likely the same. Did you **try** to use ui:repeat instead of c:foreach? – Kukeltje Apr 12 '16 at 07:53

0 Answers0