when you want to refer apex class variables in the visual force page we need to use getter & setter methods.
public class example{
string name;
}
get method :
when visualforce page want to get the value of a variable defined in the apex.it will invoke get method of that variable.
Ex :
<apex:outputlable>{!myname}</apex:outputlable>
↕
This variable defined in apex class
In this above statement visualforce page is trying to use myname variable which is declared in apex class.so it is invoke automatically getMyname() method in the apex class and this method will return the value of that.
public class example
{
string name;
public void set(string name)
{
this.name=name;
}
//setter method this will take the value from the visualforce page and stores to the apex variable name
public string getName()
{
return name:
}
}
// getter method this method will return a value to a visualforce page whenever a name variable is called.
Ex:
public class example1
integer no;
public void set(string integer no)
{
this.no=no;
}
public integer getNo()
{
return no;
}
}
No comments:
Post a Comment