I'm having trouble getting actionSupport to refresh a SelectOptions field on my Visualforce page.
I have two SelectOptions fields: one for a custom Site object and one for Account. The account options list field starts empty and disabled. When the user selects a Site, I want to retrieve the accounts, build the SelectOptions list, enable the field and refresh.
I am trying actionSupport but the retrieve is not working: the account options field is enabled but it remains empty.
Any thoughts on where I'm going wrong?
Here's the Visualforce page:
<apex:page controller="AttendanceEntry">
<apex:form id="theForm">
<apex:pageBlock title="Attendance Entry" id="theBlock">
<apex:pageBlockSection columns="2" collapsible="false" id="filterSection">
<apex:pageBlockSectionItem>
<apex:outputLabel value="Site" />
<apex:selectList value="{!selectedSite}" size="1">
<apex:selectOptions value="{!siteValues}" />
<apex:actionSupport event="onchange" action="{!selectAcctList}" rerender="filterSection" />
</apex:selectList>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
<apex:outputLabel value="School" />
<apex:selectList value="{!acctValues}" size="1" disabled="{!isAcctListDisabled}">
<apex:selectOptions value="{!acctId}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here's the controller:
public with sharing class AttendanceEntry {
public Id selectedSite { get; set; }
public List<SelectOption> acctValues { get; set; }
public Id acctId { get; set; }
public Boolean isAcctListDisabled { get; set; }
public List<SelectOption> siteValues {
get {
if (siteValues == null) {
siteValues = new List<SelectOption>();
siteValues.add(new SelectOption('', '--None--'));
for (Site__c s : [SELECT Name FROM Site__c]) {
siteValues.add(new SelectOption(s.Id, s.Name));
}
}
return siteValues;
}
set;
}
// Constructor
public attendanceEntry(){
isAcctListDisabled = true;
}
// Get accounts in the selected region. Executed by actionSupport whenever site field is changed.
public void selectAcctList() {
acctValues = new List<SelectOption>();
if (selectedSite != null) {
for (Account acct : [SELECT Name FROM Account WHERE Site__c = :selectedSite]) {
acctValues.add(new SelectOption(acct.Id, acct.Name));
}
isAcctListDisabled = false;
} else {
isAcctListDisabled = true;
}
}
}