I have 2 selectList on each row of a table. When the first one is changed, I need to modify the selectOptions of the second one. Currently, the ActionSupport is only called on one line and if the second selectList is changed from Null to any value.
Here is the code for the Apex page :
<apex:outputPanel styleClass="form-group" id="detailsDiv">
<span class="col-xs-4">{!$ObjectType['MyCustomObject__c'].fields['Details__c'].Label}</span>
<div class="col-xs-8">
<table border="0">
<apex:repeat value="{!convWrapper.Details}" var="detailsId">
<tr>
<td>
<apex:selectList value="{!convWrapper.Details[detailsId].someObject__c.Field1__c}" size="1">
<apex:selectOptions value="{!convWrapper.Details[detailsId].ListOfFields1}" />
<apex:actionSupport event="onchange" action="{!field1Changed}" reRender="detailsDiv">
<apex:param name="DetailsIdName" value="{!detailsId}" assignTo="{!detailsIdChanged}"/>
</apex:actionSupport>
</apex:selectList>
</td>
<td>
<apex:selectList value="{!convWrapper.details[detailsId].someObject__c.Field2__c}" size="1" >
<apex:selectOptions value="{!convWrapper.details[detailsId].ListOfFields2}"/>
</apex:selectList>
</td>
<td>
</td>
</tr>
</apex:repeat>
</table>
</div>
</apex:outputPanel>
And the code for the Controller :
public void field1Changed() {
System.debug('field1Changed');
if (convWrapper != null) {
convWrapper.Details.get(detailsIdChanged).someObject__c.Field2__c = null;
convWrapper.Details.get(detailsIdChanged).ListOfFields2 = convWrapper.getListOfFields2FromField1(convWrapper.Details.get(detailsIdChanged).someObject__c.Field1__c);
}
}
UPDATE
Here is the code for getListOfFields2FromField1 :
public List<SelectOption> getListOfFields2FromField1(String field1) {
List<SelectOption> listFields2 = new List<SelectOption>();
if (String.isNotBlank(field1)) {
listFields2.add(new SelectOption('---', '---'));
if (Field1ToField2Map.containsKey(Field1)) {
for (FieldObject2 field2 : Field1ToField2Map.get(Field1)) {
if (field2 != null && field2.name__c != null) {
listFields2.add(new SelectOption(field2.Id, field2.name__c));
}
}
}
}
return listFields2;
}