function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MythiliMythili 

How to get the checkbox value (whether checked or unchecked) in controller from vf page?

Hi,
How to get the checkbox value (whether checked or unchecked) in controller(apex) from visualforce page? I should get this value in controller method as soon as I click the checkbox. Please note that the checkbox is displayed in page through wrapper class.
I currently use action:support in page and invoke the method from class on click of the checkbox but I am unable to get the checkbox's checked or unchecked value. I only get the checkbox's old value.
Any help is appreciated! Thanks.
RD@SFRD@SF
Hi Mythili,

Can you check,
1. If the get and set functions are set int he controller for the check box.
2. If you have used actionRegion tag, can you verify if the check box value is in the actionRegion tags. If not please change the tags appropriately.

Can you paste your controller and vf page would easier to debug it.

Hope it helps,
RD
MythiliMythili
Hi Deepak, Thanks for your response. Yes, I have taken care of both the points mentioned by you. I wont be able to post the original full code hence pasting the part of the code. It is something like this: public class CheckBoxCase{ public Boolean isChecked{get;set;} public Boolean isSelect{get;set;} public void invokeMethod(){ system.debug('*****isCheck '+isChecked); } }
RD@SFRD@SF
Hi Mythili,

Just one more thing, what is the value set in the VF page to the input field?
MythiliMythili
Here it is:
<apex:inputCheckBox value={!isSelect}>
<apex:actionsupport event="onclick" action="{!invokeMethod}">
<apex:param value="{!isSelect}" assignTo="{!isChecked}"/>
</apex:actionSupport>
</apex:inputCehckbox>

public class CheckBoxCase{
public Boolean isChecked{get;set;}
public Boolean isSelect{get;set;}
public void invokeMethod(){
system.debug('*****isCheck '+isChecked);
}
}
RD@SFRD@SF
Hi Mythili

If you are trying to read the value of the check box then this code would be enough no need to use the <apex:param> tag
 
<apex:inputCheckBox value={!isSelect}>
<apex:actionsupport event="onclick" action="{!invokeMethod}">
<apex:param value="{!isSelect}" assignTo="{!isChecked}"/>
</apex:actionSupport>
</apex:inputCheckbox>

public class CheckBoxCase{
public Boolean isChecked{get;set;}
public Boolean isSelect{get;set;}
public void invokeMethod(){
//system.debug('*****isCheck '+isChecked);
system.debug('*****isCheck '+isSelect);
}
}

Can you please tell if there is a need to use param tag?
Hope it helps
RD