0

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.

Vasil Lukach
  • 3,658
  • 3
  • 31
  • 40
  • Tried without a `ui:repeat`? With a different component than `selectBooleanCheckbox` and if the error is from `#{myBean.isObjectSelected(object)}` it is normal the ajax listener is not called. Your question is not related to any of the tags but to EL. So post the error you get in google and start reading... – Kukeltje Dec 06 '18 at 09:02
  • yep, tried using c:foreach too. Same error shown. I am not sure how else would be effective to iterate a list of objects. – Nik Mohamad Lokman Dec 06 '18 at 09:03
  • 1
    Possible duplicate of [javax.el.PropertyNotWritableException: Illegal Syntax for Set Operation](https://stackoverflow.com/questions/14540153/javax-el-propertynotwritableexception-illegal-syntax-for-set-operation) – Kukeltje Dec 06 '18 at 09:08
  • The value of the selectBooleanCheckbox is not taken from any variable. In the isObjectSelected method, I have to check certain values in the Object and later returns a true or false, but thanks for the finding ! – Nik Mohamad Lokman Dec 06 '18 at 09:15
  • You can decorate your objects with a class having a simple `boolean selected` property with corresponding getters and setters. Then change your `ui:repeat value="#{myBean.myObjectDecorators}" var="objectDecorator"` and your `p:selectBooleanCheckbox value="#{objectDecorator.selected}"` – Selaron Dec 06 '18 at 09:49
  • The duplicate is still valid. No, it is not set via a variable but set/get via a 'property'. Properties need getters and setters like in the duplicate and what you use are not getters and setters. @Selaron describes a solution. And like stated, removing the ajax does not solve it, not using a repeat but with a fixed value does not make it work. Using an `h:inputText` would result in the same error. (al steps you shold normally do in creating a [mcve] Hence your title and all tags are sort of not 'on topic'.... Cheers – Kukeltje Dec 06 '18 at 10:52
  • Your solution is the common solutions provided by others @Selaron, since there is no other way I could think of, I did the same as you suggested but instead of a class, i created a map to store the boolean value for each object and it works ! Thank you for the solution :D – Nik Mohamad Lokman Dec 14 '18 at 08:14
  • then what would be the appropriate title and tags for this question @Kukeltje? – Nik Mohamad Lokman Dec 14 '18 at 08:17
  • try doing the things to the content of the question that I mentioned above. Then you'll see lots of things in the tags and title are not related. And having learned now (in the first comment) that this is an EL thing, you are sort of automatically left with a good title and tags. Please try. – Kukeltje Dec 14 '18 at 09:01

1 Answers1

1

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>