Usage of apex program with within visual force page
1)When you want to call Apex class in visual force page we have to declare in the following format.
<Apex: page controller = “class name”>
Whenever we call a visual force page in which controller.
Attribute is defined it will first create an object for the apex class which is defined in controller.
2)When object is created for the apex class first it invokes the constructor.
Referring to the apex class members in visual force:
When you want to refer apex class variable in the visual force page we need to use getter & setter methods.
Public class example
{
String Name;
}
Get method:
When visual force page wants to get the value of a variable defined in the apex. It will invoke get method of that variableEx:
< apex: output label > {! my name} </apex: output label >
↕
This is a variable defined in apex class.
In the above statement visual force page is typing to use my name variable which is declared in apex class. So it is invoked automatically get my name () 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;
}
Public string get name ()
{
Retune name;
}
}
Ex:
Public class example 1
{
Integer no;
Public void set (string integer no)
{
This no = no;
}
Public integer get no()
{
return no;
}
}
No comments:
Post a Comment