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
Sarah FordSarah Ford 

Getters and Setters are never called before ActionMethod (immediate="false")

This should be so simple but I cannot figure out what is wrong at all. I have simplified my controller and visual force page to simple test fields and methds but I still cannot get my getters or setters to execute. My actionMethod is called but these setters and getters which should execute before never do. I am not getting any exception or error messages in my logs
<apex:page controller="dummyController" docType="html-5.0">
    <apex:pageBlock >
    <apex:form id="form">
	<apex:input value="{!word}"/>    
        <apex:commandButton action="{!initLineItems}" value="Update"/> 
    </apex:form>
     </apex:pageBlock>
</apex:page>
 
public class dummyController {
       
    public String word {get;set;}
    

    
    public void setWord(String s){
       System.debug('in the set for word');
        word = s;
    }
    public String getWord(){
        System.debug('in the get for word');
        return word;
    }
     public PageReference initLineItems(){
        System.debug('ACTION METHOD CALLED');
         return null;
    }

}
Best Answer chosen by Sarah Ford
Rajiv Penagonda 12Rajiv Penagonda 12
I see that you have created both the setter, getter functions as well as the {get;set;} in the variable definition. This will be an issue because then Salesforce will not know which one to bind with. See the updated controller below:
 
public class TestVFPage2Controller {
    private String word = '';

    public void setWord(String s){
       System.debug('in the set for word');
        word = s;
    }

    public String getWord(){
        System.debug('in the get for word');
        return word;
    }

    public PageReference initLineItems(){
        System.debug('ACTION METHOD CALLED');
        System.debug('^^^ ' + word );
        return null;
    }
}

The setter/getter methods are invoked, when the member variable is made private and {get;set;} is removed from its definition. Hope this helps.