Scenario:
This is a common requirement to pass the values through visualforce page to apex controller and get the date from Apex controller to VF Page.
Solution:
Using the Get And Set Methods to full fill this requirement.
Apex Controller:
Visualforce Page:
<apex:page controller="sgmethods"> <apex:form > <apex:outputlabel >Enter Your Name:</apex:outputlabel> <apex:inputtext value="{!name}"/> <apex:commandButton value="Submit" rerender="page"/><br/><br/> <apex:outputLabel id="page">Your Name Is:{!name}</apex:outputLabel> </apex:form> </apex:page>
Visualforce Page:
public class sgmethods { public String Name; Public String getname(){ return name; } public void setname(string name){ this.name=name; } }Result: