Context
I want to show a pageblocktable with two input columns, Activity Type and Work Country, both populated with custom picklists as shown in the visualforce code below.
Each row represents a Period object, and has its own instance of a PeriodController. For each row, I want the second picklist Work Country to be dependent on the value selected in the first, based on logic that I want to define in apex.
Code
page:
<apex:form id="theForm">
<apex:pageBlockTable value="{!c.periodControllers}" var="periodController" rendered="{!c.periodControllers.size>0}">
<apex:column >
<apex:selectList value="{!periodController.period.Activity_Type__c}" size="1" id="work_type" required="true" >
<apex:selectOptions value="{!periodController.soActivities}"/>
<apex:actionSupport event="onchange" action="{!periodController.updateDynamicPicklists}" rerender="work_country"/>
</apex:selectList>
</apex:column >
<apex:column >
<apex:outputPanel id="work_country">
<apex:selectList value="{!periodController.period.Work_Country__c}" size="1" disabled="{!periodController.soWorkCountries.size==0}">
<apex:selectOptions value="{!periodController.soWorkCountries}"/>
</apex:selectList>
</apex:outputPanel>
</apex:column>
</apex:pageBlockTable>
</apex:form>
PeriodController:
public PageReference updateDynamicPicklists() {
System.debug( this.period.Activity_Type__c );
return null;
}
public SelectOption[] soWorkCountries {
get {
// logic that determines what work countries to return depending on activities and other parameters
}
}
Problem
When user changes the value of the first picklist, the action is executed, but in the controller, the value of period.Activity_Type__c (see System.debug statement in the controller code), is not updated. So the right cell of the table is rerendered, but the picklist is not populated with the right values. I've tried actionregions, but this doesn't work either. What am I doing wrong here?