I have a custom object(survey__c) and custom field which holds the picklists values of the month (month__c). i want to use these picklist values in vf page…. i am using a custom controller in vf page …..can anyone help in resolving this issue with an example .
vf page :
<apex:selectList id="Months" value="{!Survey__c.Month__c}" size="1" required="true">
<apex:selectOptions value="{!months}"/>
</apex:selectList>
<p/>
controller :
public List<SelectOption> getMonths()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = Survey__c.Month__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
it is giving error as –
Unknown property : 'CommunitySurveyContrller.Survey__c'
Best Answer
Assuming Survey__c is what you are trying to populate, you need to define a variable/property in your controller, i.e.:
public Survey__c survey {get; set;}
then in your constructor, instantiate it, i.e.:
public CommunitySurveyContrller() { survey = new Survey__c(); }
then in your VF page, access/connect it, i.e.:
<apex:selectList id="Months" value="{!survey.Month__c}" size="1" required="true"> <apex:selectOptions value="{!months}"/> </apex:selectList>
hope this helps.