You need to sign in to do that
Don't have an account?
mamidi mahesh
execution of getter methods in apex controller class
my requirement is that i have to get the one value from visualforce page and i have to set that value to instance variable. instance variable is
public String sscradio;
my code is below
public class MyController{
public String sscradio;
private final Candidate__c candRec;
public MyController(ApexPages.StandardController stdController){
this.candRec=(Candidate__c)stdController.getRecord();
System.debug(' we are in mycontroller constructor');
}
public String getSscradio(){
System.debug(' we are in mycontroller getter method');
return sscradio;
}
public void setSscradio(String sscradio){
System.debug(' we are in mycontroller setter method');
this.sscradio=sscradio;
}
public void submit(){
if(sscradio=='Yes'){
candRec.SSC_Certificate_submitted__c='Yes';
}else{
candRec.SSC_Certificate_submitted__c='No';
}
System.debug(' we are in mycontroller submit()');
update candRec;
}
}
when i save the vf page object is creating for controller class Mycontroller. and after saving if i go and see the debug logs, first constructor is executed,after that getter method is executed. when we click on submit in vf page then again getter method is being executed after that setter method is executed after that submit() is executed, after that again getter method is executed. why getter method is being executed many times for one instance variable.
vf page conde is below
<apex:page standardController="Candidate__c" extensions="MyController"> <apex:form > <apex:pageBlock title="Survey form"> <apex:pageBlockSection title="Certificate Details" columns="1"> <apex:selectRadio label="SSC Certificate Submitted?" value="{!sscradio}"> <apex:selectOption itemlabel="Yes" itemvalue="Yes"/> <apex:selectOption itemLabel="No" itemvalue="No"/> </apex:selectRadio> </apex:pageBlockSection> </apex:pageBlock> <apex:commandButton value="submit" action="{!submit}"/> </apex:form> </apex:page>
please could any one explain that why getter method is being executed many times for one instance variable.
public String sscradio;
my code is below
public class MyController{
public String sscradio;
private final Candidate__c candRec;
public MyController(ApexPages.StandardController stdController){
this.candRec=(Candidate__c)stdController.getRecord();
System.debug(' we are in mycontroller constructor');
}
public String getSscradio(){
System.debug(' we are in mycontroller getter method');
return sscradio;
}
public void setSscradio(String sscradio){
System.debug(' we are in mycontroller setter method');
this.sscradio=sscradio;
}
public void submit(){
if(sscradio=='Yes'){
candRec.SSC_Certificate_submitted__c='Yes';
}else{
candRec.SSC_Certificate_submitted__c='No';
}
System.debug(' we are in mycontroller submit()');
update candRec;
}
}
when i save the vf page object is creating for controller class Mycontroller. and after saving if i go and see the debug logs, first constructor is executed,after that getter method is executed. when we click on submit in vf page then again getter method is being executed after that setter method is executed after that submit() is executed, after that again getter method is executed. why getter method is being executed many times for one instance variable.
vf page conde is below
<apex:page standardController="Candidate__c" extensions="MyController"> <apex:form > <apex:pageBlock title="Survey form"> <apex:pageBlockSection title="Certificate Details" columns="1"> <apex:selectRadio label="SSC Certificate Submitted?" value="{!sscradio}"> <apex:selectOption itemlabel="Yes" itemvalue="Yes"/> <apex:selectOption itemLabel="No" itemvalue="No"/> </apex:selectRadio> </apex:pageBlockSection> </apex:pageBlock> <apex:commandButton value="submit" action="{!submit}"/> </apex:form> </apex:page>
please could any one explain that why getter method is being executed many times for one instance variable.