2

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?

0

What you need to do is, pass on the desired value using apex:param in

Apex:Param is used to pass values to the controller using actionSupport. Read more: More about apex Param

  • I've tried that: <apex:actionSupport event="onchange" action="{!periodController.updateDynamicPicklists}" rerender="work_country"/> <apex:param value="{!periodController.period.Activity_Type__c}" assignTo="{!periodController.period.Activity_Type__c}"/> </apex:actionsupport> But it doesn't help. Maybe I'm doing it wrong, it seems strange to me that value and assignTo have the same value. – Stijn Nov 10 '14 at 9:38
  • Someone just deleted my answer. Add <apex:param value="{!periodController.period.Activity_Type__c}" assignTo="{!periodController.period.Activity_Type__c}" name="something"/> to your param – Sforce.Ninja Nov 10 '14 at 11:16
  • When I do that, the value of periodController.period.Activity_Type__c is reset to its original value (on page load) every time. Funny thing -- it works as expected if I replace <apex:selectList> with <apex:inputField>. But then I can't control the picklist values that are shown in the interface. – Stijn Nov 10 '14 at 13:30
0

I had a similar problem and found that using an actionFunction usually worked better. Could you try this to see if it works for you too?

Instead of doing the update and reRender with the action support, call an actionFunction instead which does the updating and reRendering.

<apex:actionSupport event="onchange" onComplete="actUpdateDynamicPicklists()" rerender="none"/>

somewhere else in your code:

<apex:actionFunction action="{!periodController.updateDynamicPicklists}" name="actUpdateDynamicPicklists" rerender="work_country"/>
0

problem with rerender attribute, below link will help you http://sfdcmaniac.blogspot.in/2015/10/passing-parameters-to-controller-and.html

  • Welcome to the community but it will be great if you can post answer from any url because that link may change by the time. you can add link for ref. only – Himanshu Nov 6 '15 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.