jsfprimefacesuirepeatselectbooleancheckbox

selectBooleanCheckBox in ui:repeat doesn't call listener


I am trying to populate selectBooleanCheckbox values using ui:repeat as the values are taken from a list. The checkbox values are assigned fine, but the listener is not called when I change the selectBooleanCheckbox value. I also got this error when changing the value

Illegal Syntax for Set Operation: javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation

Here is my code

 <ui:repeat value="#{myBean.myObjects}" var="object">                                                           
    <p:selectBooleanCheckbox 
       value="#{myBean.isObjectSelected(object)}">                                                      
          <p:ajax update="growl"                                                            
             listener="#{myBean.doSomethingtoObject(object)}" />                                                        
    </p:selectBooleanCheckbox>                                                  
    <h:outputText value="#{object.name}" />
</ui:repeat>

The issue comes from value="#{myBean.isObjectSelected(object)}" part. When I removed that part the error is gone and the listener is called fine. But how else would I get the checkbox value without it? Even if I straight away assign the value to be #{true} the listener would not be called. I found similar issues but not with ajax listeners.


Solution

  • Apparently, the selectBooleanCheckBox must have a predefined value and cannot be populated by calling a method. Solved this by using a Map and keeping the TRUE or FALSE value inside.

    <ui:repeat value="#{myBean.myObjects}" var="object">                                                           
        <p:selectBooleanCheckbox 
           value="#{myBean.objectMap[object]}">                                                      
              <p:ajax update="growl"                                                            
                 listener="#{myBean.doSomethingtoObject(object)}" />                                                        
        </p:selectBooleanCheckbox>                                                  
        <h:outputText value="#{object.name}" />
    </ui:repeat>