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
B1B1 

inputText and getter/setter methods

how does getter and setter methods have relationship between visualforce page and a controller...?

Himanshu ParasharHimanshu Parashar

Getter Methods:

                            Getter methods return values from a controller. Every value that is calculated by a controller and displayed in a page must have a                                         corresponding getter method, including any Boolean variables. in other simple words The "get" method is used to pass data from your                             Apex code to your Visualforce page

 

Setter Methods:

                           Setter methods pass user-specified values from page markup to a controller. Any setter methods in a controller are automatically                                        executed before any action methods. In other simple words The "set" method is used to pass values from your visualforce page to the                               controller

 

 

For Example in below scenerio userinput will display "Sample Text" as output.

 

public class getsetTest
{  
    public String userinput;
    public String getuserinput()
    {
        return 'Sample Text';
    }
   
    public void setuserinput(String userinput)
    {
        this.userinput = userinput;
    }   
}

 

<apex:page controller="getsetTest">
  <apex:form>
    <apex:outputpanel id="display">
        <apex:outputtext value="The name entered is {!userinput}"/>
    </apex:outputpanel>                   
  </apex:form>    
</apex:page>

 

 

    Make sense ?