2

I have a collection List<boolean> and I want to display this list on VF page.

But the issue is , merege variable is working fine in <apex:outputText>, not in <apex:inputCheckBox>.So my page isn't getting saved.

ApexClass:

public class TestController {

    public List<boolean> boolList {get; set;}

    public TestController () {
        boolList = new List<boolean>{true, false, true};
    }
}

VF Page:

<apex:page controller="TestController">
    <apex:form >
     <table> 
    <tr>
      <apex:repeat value="{!boolList}" var="entry">
        <td>
           <apex:outputText value="{!entry}"/>
           <apex:inputCheckBox value="{!entry}"/>  <!-- Here I am getting unknown Prperty issue-->                              
        </td>
      </apex:repeat>  
    </tr>
</table>  
</apex:form>

</apex:page>

I know, to use any variable in <apex:inputTextBox>, variable has to be merge variable. {get; set;}. But we have declared boolList as getter and setter. and we are iterating over that boolist in <apex:repeat>.

any idea?

  • Just out of curiosity, what is your purpose for a list of booleans? – Mark Pond Jul 14 '15 at 22:21
2

Look at the docs: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_inputCheckbox.htm

the attribute type for value is object, you are passing boolean instead of an object

value Object A merge field that references the controller class variable that is associated with this checkbox. For example, if the name of the associated variable in the controller class is myCheckbox, use value="{!myCheckbox}" to reference the variable. 10.0 global

Create a wrapper class and modify your code as pasted below:

<apex:page controller="TestController">
    <apex:form >
     <table> 
    <tr>
      <apex:repeat value="{!boolwrap}" var="entry">
        <td>
           <apex:outputText value="{!entry.boolval}"/>
           <apex:inputCheckBox value="{!entry.boolval}"/>  <!-- Here I am getting unknown Prperty issue-->                              
        </td>
      </apex:repeat>  
    </tr>
</table>  
</apex:form>

</apex:page>

public with sharing class TestController {

    public List<boolean> boolList {get; set;}

    public List<booleanclass> boolwrap {get;set;}
    public Map<String, List<Product2>> myMap {get; set;}

    public TestController() {
    boolwrap  = new List<booleanclass>();
    boolList = new List<boolean>{true,false,true};
        for(boolean b: boollist){
            boolwrap.add(new booleanclass(b));
        }
    }

    public class booleanclass{
    public boolean boolval{get;set;}

    public booleanclass(boolean bool){
    boolval = bool;
    }

    }
} 
|improve this answer|||||
1

The value attribute must reference a field that has a get and set method i.e. an Apex property.

Here is one way to accomplish that for your case:

public class TestController {

    public class BooleanAdapter {
        public Boolean value {get; set;}
        BooleanAdapter(Boolean value) {
            this.value = value;
        }
    }

    public List<BooleanAdapter> boolList {get; set;}

    public TestController () {
        boolList = new List<BooleanAdapter>{
                new BooleanAdapter(true),
                new BooleanAdapter(false),
                new BooleanAdapter(true)
                };
    }
}

with this Visualforce:

<apex:repeat value="{!boolList}" var="entry">
  <td>
     <apex:outputText value="{!entry.value}"/>
     <apex:inputCheckBox value="{!entry.value}"/>
  </td>
</apex:repeat>  
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.