You need to sign in to do that
Don't have an account?
Chandramohan Yetukuri 1
Error while retrieving a value from apex class to VF page.
I have a simple apex class like this. I am trying to retrieve a string value from apex class in my vf page(Find below). I am getting the error
"Error: Unknown property 'String.empName"
Please help to resolve the below issue.
Apex Class:-
public class constructorClass {
public string empName;
public String getempDetails()
{
empName = 'Chandra';
return empName;
}
}
VF Page:-
=======
<apex:page controller="constructorClass"> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="TestConstructor"> <apex:pageBlockTable value="{!empDetails}" var="t"> <apex:column value="{!t.empName}"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
"Error: Unknown property 'String.empName"
Please help to resolve the below issue.
Apex Class:-
public class constructorClass {
public string empName;
public String getempDetails()
{
empName = 'Chandra';
return empName;
}
}
VF Page:-
=======
<apex:page controller="constructorClass"> <apex:form > <apex:pageBlock > <apex:pageBlockSection title="TestConstructor"> <apex:pageBlockTable value="{!empDetails}" var="t"> <apex:column value="{!t.empName}"/> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Use
OR you could use
public string empName{get;set;} instead of public string empName;
in this case the code didnt work because in function
you have returned a reference to empName variable. but since that variable didnt have get method , you couldn't display in vf page.
If you have used just return 'Chandra' the code would have worked
Let me know if you need further help.
Thanks and Regards,
Shiva RV