I have two picklists in a visualforce page with a controller extension:
<apex:actionFunction name="updateModelList" rerender="modelSelect"/>
....
<apex:selectList value="{!selectedBrand}" multiselect="false" size="1" onChange="updateModelList();">
<apex:selectOptions value="{!brandObjects}"/>
</apex:selectList>
...
<apex:selectList id="modelSelect" value="{!selectedModel}" multiselect="false" size="1">
<apex:selectOptions value="{!modelObjects}"/>
</apex:selectList>
Then there is some controller functions code that creates the Options for these selects. This works as long as i don't touch the second picklist. Values are correctly updated and everything is fine.
Basically what I noticed is that whenever I trigger the onChange event on the first picklist and I changed the value on the second picklist, values on the second one are not correctly updated as the controller variable selectedBrand is set to '' (empty string) whereas the variable selectedModel is set to null. This causes the second picklist to be empty after this action.
Any insight?
edit: further info, the controller has two getter methods that return a List of SelectOption one for each picklist.
edit #2: i found out the problem, apparently VisualForce Pages invoke getter methods "randomly" so my bad I had a side effect which initialized the placeholder variable in one of these methods.
Thank You.
onChange="updateModelList();
So when you make a change to{!brandObjects}
there should be a corresponding change to{!modelObjects}
. Perhaps if you posted the code for your controller, something might be apparent as the cause.