0

I'm creating a carousel component, with selectManyCheckbox on each slide:

        <h:form>
            <p:carousel var="question" 
                        value="#{quizView.questions}" 
                        numVisible="1" 
                        responsive="true">
                <p:selectManyCheckbox 
                     value="#{question.options}"
                     layout="responsive"
                     columns="1">
                    <f:selectItems value="#{question.options}" 
                                   var="option" 
                                   itemLabel="#{option.text}"
                                   itemValue="#{option.text}"/>
                    <p:ajax listener="#{quizView.itemSelected}" update="@form"/>
                </p:selectManyCheckbox>
            </p:carousel>
        </h:form>

I would like to catch the change on the backing bean and update the property on the option object. Backing method is called correctly, but I don't know how to move from here:

public void itemSelected(AjaxBehaviorEvent event) {
    questions = questionService.getQuestions(quizURL);
    // figure which question from event
    // figure out which option from event
    // update the property on the option
}

the Option class looks as follows:

public class Option {
    private Boolean correct;
    private Boolean selected;
    private String text;

    // Getters and Setters
}

What I would like is to set the property selected to true if this option is selected

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
learnAndImprove
  • 1,339
  • 4
  • 15
  • 25
  • *"update the property on the option"* Why? JSF has already done that for you. – BalusC Feb 11 '18 at 18:16
  • I've edited a question with more detail. I guess that JSF can automatically update only a boolean property? I'll try to change the `itemValue` to `option.selected` and see if I got it right – learnAndImprove Feb 11 '18 at 18:23
  • 1
    Wait, you're using #{question.options} as both "selected values" and "available values". This makes no sense. You should use #{question.options} as "available values" and collect the "selected values" in another property. – BalusC Feb 11 '18 at 18:25
  • ah, very true, thanks. This was not obvious to me, perhaps you can add it as an answer and I can accept it – learnAndImprove Feb 11 '18 at 18:34

0 Answers0