In my visualforce page I have two command button. I want to store boolean value into database against those radio button. I have chosen the field type as 'checkbox'. Please help me.
My vf code is
<apex:page standardStylesheets="false" controller="RadioButtonTestController" showHeader="false" sidebar="false">
<apex:form >
<div align="center">
<apex:selectRadio value="{!Country}" >
India <apex:selectOption itemValue="true"></apex:selectOption>
China <apex:selectOption itemValue="false"></apex:selectOption>
<apex:actionSupport event="onchange"
action="{!checkSelectedValue}"
reRender="none"/>
</apex:selectRadio>
<apex:commandButton value="Show country" action="{!showCountry}"/>
</div>
</apex:form>
My Controller is: `
public class RadioButtonTestController
{
public Boolean Country{get; set;}
public void checkSelectedValue()
{
system.debug('Selected value is: '+ Country);
}
public void showCountry()
{
String caseId = ApexPages.currentPage().getParameters().get('CaseID');
list<Storing_Location__c> str = [Select Country__c from Storing_Location__c where CaseNumID__c=: caseId];
Storing_Location__c obj = new Storing_Location__c();
if(str.size()>0)
{
obj.Id = str[0].Id;
}
obj.Country__c = Country;
system.debug('Selected value is:***********************:::'+Country);
}
}
Best Answer
I got a solution myself
The controller should be:
Here the database field "Country__c" is checkbox type. So it takes only Boolean value. If User select "India" then field "Country__c" will be checked otherwise not.