[SalesForce] apex:inputCheckBox selected attribute is not working

i write a small snippet related to apex:inputCheckBox

<apex:inputCheckbox onclick="callRemoteFunction(this,{!num})" selected="{!isItemSelected}"/>

i am facing error

 Unknown function isItemSelected. Check spelling

in my custom controller there is a function named isItemSelected here is definition

public Boolean isItemSelected(){
    System.debug('---coming here---');
    return false;
    } 

can anyone please explain why i am facing this issue when there is a corresponding function in controller ??

Best Answer

You need to change your method to:

public Boolean getIsItemSelected(){
    System.debug('---coming here---');
    return false;
}

Methods that can be accessed in Visualforce need to be defined as getters:

One of the primary tasks for a Visualforce controller class is to give developers a way of displaying database and other computed values in page markup. Methods that enable this type of functionality are called getter methods, and are typically named getIdentifier, where Identifier is the name for the records or primitive values returned by the method.

Related Topic