0

I have checkboxes on my vf page

<apex:inputCheckbox id="checkboxShowP" value="{!P}" onchange="show(this);"/>

In the controller class

public boolean P{get;set;}

I want to bind this checkbox value to a boolean variable. But when I display the P value of apex class it is showing up as null. Is it possible to bind variable values in this way?

4
  • Can you add your relevant VF code here?
    – Sumuga
    Dec 29, 2017 at 13:31
  • i added the code. The tags are not being displayed for some reason
    – Rimii
    Dec 29, 2017 at 13:32
  • wrap the markup inside a "pre" tag. like <pre> YOUR HTML CODE </pre>
    – Sumuga
    Dec 29, 2017 at 13:32
  • I removed the tag brackets from my code
    – Rimii
    Dec 29, 2017 at 13:35

1 Answer 1

3

Looks like you have not initialised the value for "P". Initialise the value in the constructor.

VF Page:

<apex:page controller="CheckboxController">
    <apex:form >
        <apex:inputCheckbox id="checkboxShowP" value="{!P}" onchange="show(this);"/>
    </apex:form>
</apex:page>

Apex Class:

public with sharing class CheckboxController {

    public Boolean P{ get; set; }

    public CheckboxController(){
        this.P = true;
    }
}

Checkbox

Do check the Apex and VF trailhead for an understanding of dynamic bindings.

Custom Controllers : https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_custom.htm

1
  • I already tried this. However, the value of the boolean remains as what was initialized in the Constructor. It does not change according to the check/uncheck in VF page @Sumuga
    – Rimii
    Jan 2, 2018 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .