Write an example for getters method using visual force and apex class
Example class:
Public class example
{
String name;
Public string get name ()
{
}
}
Example page:
< apex: page controller = “example”>
< apex: output label > {! name} </apex: output label>
<apex: page >
- in the above program when the page is loaded first it creates an object for the example class.
- when output label calls {! name} in the VF page it invokes gate name () method in the controller
Class. Which will return “Sam”
Output:
Sam
1. Apex class example:
Public class example{
String name;
Public example ()
{
Public string get name ()
{
Return name;
}
}
Example page:
< apex: page controllers = “example”>
< apex output label > your name is {! name} </apex: output label >
</apex page>
Output:
Hari
Writing the values into Apex variable from visual force page:
This is called read/write operation of the variable.Ex: {! age}
Public void set age (integer age)
{
This name = name;
}
Write an apex class to return the value to visual force page:
Apex class:Public class example 1
{
Public integer age;
Public example1()
{
Age = 10;
}
Public integer gets Age ()
{
return age;
}
Public string gets Name ()
{
Return ‘Sam Kumar’;
}
}
VF page:
< apex: page controllers = “example1”>
< apex: output Label> {! age} </apex: output Label>
<apex output label> {! name} </apex: output Label>
</apex: page >
No comments:
Post a Comment