I've got a simple VisualForce page with a form that has one custom picklist. My controller successfully populates the custom picklist and the page renders fine. But when I click on the CommandButton after selecting something int he picklist, the selected value in the picklist doesn't get set and the action method of the CommandButton thinks it's null.
I'm at a loss. I'm sure it's something simple, but I've checked and rechecked it. Here is the code.
VisualForce page:
<apex:page controller="RequestCoverage" showHeader="false" sidebar="false" showChat="false">
<apex:form >
<script type="text/javascript">
var isClicked = false;
function checkDoubleSubmit(obj){
if (isClicked) {
return false;
}else {
isClicked = true;
obj.className = 'btnDisabled';//only shows the button as disabled.
return true;
}
}
</script>
<apex:pageBlock >
<apex:pagemessages ></apex:pagemessages>
<apex:pageBlockSection columns="1" title="Coverage Request" collapsible="false">
<apex:pageblockSectionItem >
<apex:outputLabel >Show</apex:outputLabel>
<apex:selectList value="{!selectedOption}" size="1">
<apex:selectOptions value="{!shws}"></apex:selectOptions>
</apex:selectList>
</apex:pageblockSectionItem>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Submit Request" action="{!SaveIt}" onclick="return checkDoubleSubmit(this)" />
<apex:commandButton value="Cancel" action="{!CancelIt}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex controller:
public class RequestCoverage {
public Coverage_Request__c requestForCoverage { get; set; }
public String selectedOption { get; set; }
list<Show__c> activeShows;
Host__c h;
class ActiveShowDetail {
Id showId { get; set; }
String Show_Display_Name { get; set; }
String Show_Display_Date { get; set; }
Date showDate;
}
list<ActiveShowDetail> showOptions;
public RequestCoverage() {
// A whole bunch of code that I've left out of this post because it's not relevant.
}
public pagereference UserLoggedIn(){
// Kick the user out if a login token wasn't provided in the URL or we couldn't find the host
if (ApexPages.CurrentPage().getParameters().get('a') == null || h == null) {
pagereference page = new pagereference('/Hostlogin');
return page;
}
return null;
}
public list<selectOption> getShws(){
list<SelectOption> options = new list<SelectOption>();
// showOptions is populated in the constructor and this code works fine
// because the page is successfully rendered
if (showOptions != null) {
for (ActiveShowDetail asd : showOptions) {
options.add(new SelectOption(asd.showId + '/' + asd.Show_Display_Date,asd.Show_Display_Date + ' @ ' + asd.Show_Display_name));
}
}
return options;
}
public pagereference SaveIt() {
// This is the debug statement that is showing that selectedOption is null
// even though I selected a value in the picklist
System.debug('**** Inside of SaveIt()! selectedOption is ' + selectedOption);
return null;
}
public void CancelIt(){
h.Logged_In_Code__c = null;
update h;
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO, 'You have been logged out. Thank you and have a good day.');
ApexPages.addMessage(myMsg);
}
}
onclick
from the command button does the page behave the way you expect?