I have a requirement where I am not displaying the actual salesforce picklist field on visualforce page but rather a self created selectlist with some values.
I was able to display it on visualforce page but don't know how to fetch the user selected value and store it into another field on apex class.
Here is my visualforce code to display the picklist:
<apex:selectList value="{!AlcoholInvolvedId}" style="width:40%;" size="1">
<apex:selectOptions value="{!AlcoholInvolved}"/>
</apex:selectList>
<apex:commandButton id="Save" value="Save" action="{!saveAndContinue}"
Here is my controller class:
public String AlcoholInvolvedId { get;set; }
public List<SelectOption> AlcoholInvolved{
get
{
//Alcohol_Involved = new List<SelectOption>();
List<Selectoption> Alcoholinv = new List<selectoption>();
Alcoholinv.add(new selectOption('', '--None--'));
Alcoholinv.add(new selectoption('', 'Yes'));
Alcoholinv.add(new selectoption('', 'No'));
return Alcoholinv;
}
set {}
}
public pagereference saveAndContinue() {
Application__c app= new Application__c(
.........,
Alcohol_Involved__c= AlcoholInvolvedId,
);
insert app;
............
.............
}
Best Answer
You're setting the "value" to nothing in all the options. You need to specify a value: