I have a Visualforce page with a controlling picklist field and a dependent picklist field. Both fields are required entry during record creation, but instead of using the required
parameter on apex:inputField
, the controller is validating the fields and returning a pageMessage
if an entry is not made.
When I select a value on the controlling picklist and leave the dependent blank and submit, I get the page message as expected, but now the dependent picklist shows no values except --None--
. The controlling picklist still shows the value I selected, but the dependent has nothing for me to select, even though there should be values based on the controlling value.
The only way to get the dependent picklist values populated again is to select some other value in the controlling picklist, at which point the correct dependent values appear.
I've tried rerendering various parts of the page when the submit occurs, but nothing works. I've also omitted the rerender and that doesn't work either.
Has anyone seen this before?
I inherited this page/controller from a previous developer and there's a lot of bad code, so I have to exclude a lot of irrelevant code. The page is based on the Case standard controller and is using a controller extension.
Here is a portion of the VF page. Product_Line__c
is the controlling picklist, Version__c
is the dependent.
<apex:pageBlockSection id="pbs1" columns="2">
<apex:outputLabel id="supCasePLlbl" value="{!$ObjectType.Case.Fields.Product_Line__c.label}" styleClass="requiredField" />
<apex:outputLabel id="supCaseVlbl" value="{!$ObjectType.Case.Fields.Version__c.label}" styleClass="requiredField" />
<apex:outputPanel >
<apex:actionRegion >
<apex:inputField id="supCasePLdd" value="{!caseObj.Product_Line__c}" styleClass="support-case-form-control">
<apex:actionSupport event="onchange" action="{!checkproductline}" reRender="msgs,supCasePOS1,supCasePOS2,supCaseA1,supCaseAdd,supCaseA2,supCasePH1,supCasePH2"/>
</apex:inputField>
</apex:actionRegion>
</apex:outputPanel>
<apex:outputPanel id="supCaseVdd">
<apex:inputField value="{!caseObj.Version__c}" styleClass="support-case-form-control left-align"/>
</apex:outputPanel>
Here's the command button:
<apex:commandButton styleClass="btn btn-primary text-uppercase" value="Submit" action="{!submit}" />
Here's the extension's constructor:
public Case caseObj {get; set;}
public CustomerCommunityCaseController() {
caseObj = new Case();
init(); // does some actions that do not affect caseObj
}
Here is the method in the controller extension:
public PageReference submit() {
// validate() checks the field entries. Since I don't select a dependent field value,
// it will return false.
if (validate()) {
// save actions occurs here, I'm omitting the code.
}
return null;
}