Getter and setter methods are used to pass data from your visualforce page to your controller and vice versa.
The "get" method is used to pass data from your apex code to your visualforce page.
The set method is used to pass values from your visualforce page to the controller.
ex :
public class simplegetset {
public String userinput {get;set;}
public String getuserinput()
{
return 'John';
}
public void setuserinput(String userinput)
{
this.userinput = userinput;
}
}
<apex:page controller="simplegetset" >
<apex:form>
<apex:outputlabel value="Enter your name here"/>
<apex:inputtext value="{!userinput}">
<apex:actionsupport event="onchange" rerender="display" />
</apex:inputtext>
<apex:outputpanel id="display">
<apex:outputtext value="The name entered is {!userinput}"/>
</apex:outputpanel>
</apex:form>
</apex:page>
Visualforce requires a "getter" and "setter" to reference a variable in the controller or extension. Without a getter or setter, even public or global variables cannot be referenced in Visualforce expressions.
"get;" is basically: public *datatype* getVarName() { return varName; }
"set;" is basically: public void setVarName(*datatype* value) { varName = value; }
The "get" method is used to pass data from your apex code to your visualforce page.
The set method is used to pass values from your visualforce page to the controller.
ex :
public class simplegetset {
public String userinput {get;set;}
public String getuserinput()
{
return 'John';
}
public void setuserinput(String userinput)
{
this.userinput = userinput;
}
}
<apex:page controller="simplegetset" >
<apex:form>
<apex:outputlabel value="Enter your name here"/>
<apex:inputtext value="{!userinput}">
<apex:actionsupport event="onchange" rerender="display" />
</apex:inputtext>
<apex:outputpanel id="display">
<apex:outputtext value="The name entered is {!userinput}"/>
</apex:outputpanel>
</apex:form>
</apex:page>
Visualforce requires a "getter" and "setter" to reference a variable in the controller or extension. Without a getter or setter, even public or global variables cannot be referenced in Visualforce expressions.
"get;" is basically: public *datatype* getVarName() { return varName; }
"set;" is basically: public void setVarName(*datatype* value) { varName = value; }
No comments:
Post a Comment