You need to sign in to do that
Don't have an account?
The simplest selectlist problem
It feels that this should be something very basic, but I simply cannot get it to work.
vf code:
<apex:page Controller="IndividualAccreditationFormController" >
<apex:form >
<apex:selectList value="{!value}" size="1">
<apex:selectOptions value="{!USPersonAnswers}" />
</apex:selectList>
<apex:commandButton value="Ugh this blows" action="{!signAndRegister}"></apex:commandButton>
</apex:form>
</apex:page>
in the controller, I have a very simple:
public String value {get;set;}
and the method signAndRegister() simply tries to use the value string and assign it to an object's custom field:
public void signAndRegister() {
System.debug('Before sign and register: '+value);
if (this.value==null) {
this.value = 'was null';
}
form.USPersonText__c = this.value;
insert form;
}
Anyway, value is never getting set. Any ideas would be much appreciated.
David
I figured it out.
In the controller, the method to populate the selectlists was only passing the the second argument to the selectOption constructor, instead of two like this (because that is what I saw in every other example):
List<selectOption> options = new List<selectOption>();
Schema.DescribeFieldResult f = Object__c.Field__c.getDescribe();
options.add(new selectOption('- None -', '- None -'));
for(Schema.PicklistEntry pe : f.getPicklistValues())
{
options.add(new selectOption(pe.getLabel(), pe.getLabel()));
}
return options;
All Answers
I figured it out.
In the controller, the method to populate the selectlists was only passing the the second argument to the selectOption constructor, instead of two like this (because that is what I saw in every other example):
List<selectOption> options = new List<selectOption>();
Schema.DescribeFieldResult f = Object__c.Field__c.getDescribe();
options.add(new selectOption('- None -', '- None -'));
for(Schema.PicklistEntry pe : f.getPicklistValues())
{
options.add(new selectOption(pe.getLabel(), pe.getLabel()));
}
return options;
I am so glad I finally came across this. I spent hours with the same problem trying to figure it out to no avail. I have no idea why all the examples are like that. I guess SF needs to work a little more on their documentation.