You need to sign in to do that
Don't have an account?
reRender from selectList OnChange not functioning properly
I have multilevel selectOptions so the user can select Region, Country, StateProvince and City. I rerender each when the parent selection changesl. However, it only changes the first child of the parent. For example, if the values are "North America, US, TX, Dallas" and then change to Country to Canada, the StateProvince selections change, but the City does not rerender. Also, sometimes I click on the child field and see that it is incorrect. But when I click again, it has been changed to the correct values.
Any help appreciated. Here is my code (note that each geography has an "All" record as a valid selection).
<apex:page standardcontroller="CompetencyOwner__c" Extensions="CompetencyOwnerExt"> <apex:form > <apex:pageBlock > <apex:PageMessages /> <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> <apex:pageBlockTable var="c" value="{!CompetencyOwner__c}" title="Assign Regions"> <apex:column headerValue="Owner"> <apex:selectList value="{!selectedRole}" size="1" required="True" Style="width:150px"> <apex:selectOptions value="{!Roles}"/> </apex:selectList> </apex:column> <apex:column headerValue="Region"> <apex:selectList value="{!selectedRegion}" size="1" required="True" Style="width:150px"> <apex:selectOptions value="{!Regions}"/> <apex:actionSupport event="onchange" rerender="countryID"/> </apex:selectList> </apex:column>
<apex:column headerValue="Country"> <apex:selectList value="{!selectedCountry}" id="countryID" size="1" required="False" Style="width:150px"> <apex:selectOptions value="{!Countries}"/> <apex:actionSupport event="onchange" rerender="stateprovinceID"/> </apex:selectList> </apex:column> <apex:column headerValue="State/Province"> <apex:selectList value="{!selectedStateProvince}" id="stateprovinceID" size="1" required="False" Style="width:150px"> <apex:selectOptions value="{!StateProvinces}"/> <apex:actionSupport event="onchange" rerender="cityID"/> </apex:selectList> </apex:column> <apex:column headerValue="City"> <apex:selectList value="{!selectedCity}" id="cityID" size="1" required="False" Style="width:150px"> <apex:selectOptions value="{!Cities}"/> </apex:selectList> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
Controller:
public class CompetencyOwnerExt{
//note that this code depends upon each geography(region, country,state,city)
//having a record entry named "All"
Public CompetencyOwner__c CompOwner;
public String SelectedRole {get;set;}
public String SelectedRegion{get;set;}
public String SelectedCountry{get;set;}
public String SelectedStateProvince {get;set;}
public String SelectedCity {get;set;}
private final CompetencyOwner__c custobj;
private ApexPages.StandardController controller;
//create a constructor that extends the standard controller
public CompetencyOwnerExt(ApexPages.StandardController controller){
this.controller=controller;
this.custobj=(CompetencyOwner__c)controller.getrecord();
String CompOwnerID=ApexPages.CurrentPage().getparameters().get('ID');
CompOwner=[Select Name, OwnerRole__c,OwnerRoleID__c,Region__c,Country__c,StateProvince__c,City__c
From CompetencyOwner__c where ID=:CompOwnerID];
if(CompOwner==null) {
//this is a new competency owner
CompetencyOwner__c newComp=new CompetencyOwner__c();
insert newComp;
}
else {
//set presets from database
selectedRegion=CompOwner.Region__c;
selectedCountry=CompOwner.Country__c;
selectedStateProvince=CompOwner.StateProvince__c;
selectedCity=CompOwner.City__c;
}
} //end constructor
/********* Regions *********/
public List<selectOption> getRegions() {
List<SelectOption> regionOps=new List<SelectOption>();
List<Region__c> regionList=[Select Name from Region__c Order by Name];
for(Region__c r:regionList) {
regionOps.add(new SelectOption(r.ID,r.Name));
}
}
public String getSelectedRegion() {
return SelectedRegion;
}
public void setSelectedRegion(String SelectedRegion) {
System.debug(LoggingLevel.INFO,'??????????????? selected region set'+SelectedRegion);
this.SelectedRegion=SelectedRegion;
}
/********* End Regions *********/
/********* Countries *********/
public List<selectOption> getCountries() {
List<selectOption> CountryOps=new List <selectOption>();
List<Country__c> CountryList;
Country__c allCountries=[Select Name from Country__c Where Name='All' and Region__c=:selectedRegion Limit 1];
countryOps.add(new selectOption(allCountries.id,allCountries.Name));
CountryList=[Select Name from Country__c Where Region__c=:selectedRegion Order by Name];
for(Country__c co:CountryList) {
if(co.id!=allCountries.id) {
countryOps.add(new selectOption(co.id,co.Name)); //All value already added
}
} //end for
return countryOps;
} //end getCountries
public String getSelectedCountry() {
return SelectedCountry;
}
public void setSelectedCountry(String SelectedCountry) {
this.SelectedCountry=SelectedCountry;
}
/********* end Countries *********/
/********* State Provinces *********/
public List<selectOption> getStateProvinces() {
List<selectOption> stateProvinceOps=new List <selectOption>();
List<State_Province__c> stateProvinceList;
//get ID for All selection
State_Province__c allStateProvinces=[Select Name from State_Province__c Where Name='All' and Country__c=:selectedCountry Limit 1];
stateProvinceOps.add(new selectOption(allStateProvinces.id,AllStateProvinces.Name));
stateProvinceList=[Select Name from State_Province__c Where Country__c=:selectedCountry Order by Name];
for(State_Province__c sp:stateProvinceList) {
if(sp.id!=allStateProvinces.id) {
stateProvinceOps.add(new selectOption(sp.id,sp.Name));
}
}
return StateProvinceOps;
} //end getStateProvinces
public String getSelectedStateProvince() {
return SelectedStateProvince;
}
public void setSelectedStateProvince(String SelectedStateProvince) {
this.SelectedStateProvince=SelectedStateProvince;
}
/********* Cities *********/
public List<selectOption> getCities() {
List<selectOption> CityOps=new List <selectOption>();
List<City__c> CityList;
//default for cityList is All
City__c allCities=[Select Name from City__c Where Name='All' and StateProvince__c=:selectedStateProvince Limit 1];
cityOps.add(new selectOption(allCities.id,allCities.Name));
cityList=[Select Name from City__c Where stateProvince__c=:selectedStateProvince Order by Name];
for(City__c ci:cityList) {
if(ci.id!=allCities.id) {
cityOps.add(new selectOption(ci.id,ci.Name));
}
}
return CityOps;
} //end getCities
public String getSelectedCity() {
return SelectedCity;
}
public void setSelectedCity(String CityProvince) {
this.selectedCity=SelectedCity;
}
I don't understand what you are saying. I do have actionSupport in there with an onclick function to rerender the child field. And, the child field does rerender when I change the parent. The problem is that the changes do not cascade to the fields below the first child field. For example, if I change Region, Country rerenders to the new selectOption values but StateProvince and City do not.