[SalesForce] unable to pass parameter to controller

I have a VF page with two select lists. I'm trying to pass the value selected in the first select list to my controller method that returns a list of select options for the second select list. I'm using actionSupport component, but the parameter is not getting passed back to the controller. In my debug, the event fires on the actionSupport and I enter the method, but the parameter value is not getting passed to the controller. I think it might be related to reRender, but I haven't been able to get it to work.

Here is the VF page code:

    <apex:selectList value="{!innovationCategory}" size="1" id="cat">
        <apex:selectOptions value="{!categories}"/>
        <apex:actionSupport event="onchange" reRender="subCat" >
            <apex:param name="myParam" value="{!innovationCategory}" />
        </apex:actionSupport>
    </apex:selectList>
    <apex:selectList value="{!subCategory}" size="1" id="subCat">
        <apex:selectOptions value="{!subCategories}"/>
    </apex:selectList>

Here is the controller method:

public List<SelectOption> getSubCategories(){
    system.debug('**************** we are inside the getSubCategories method');
    string catName = Apexpages.currentPage().getParameters().get('myParam');
    system.debug('**************** catName' + catName);
    Map<String, List<SelectOption>> subCatMap = getMapOfSubCat();
    system.debug('**************** subCatMap ' + subCatMap);
    return subCatMap.get(catName);
} 

Thanks for any help.

Best Answer

You don't need a separate param inside actionSupport to pass the value.. the value field in the selectList will hold the selected value.

So in your getSubCategories method, you can directly use the innovationCategory variable.

also you can wrap the select lists inside actionRegion

<apex:actionRegion>
<apex:selectList value="{!innovationCategory}" size="1" id="cat">
    <apex:selectOptions value="{!categories}"/>
    <apex:actionSupport event="onchange" reRender="subCat" >
    </apex:actionSupport>
</apex:selectList>
</apex:actionRegion>

<apex:actionRegion>
<apex:selectList value="{!subCategory}" size="1" id="subCat">
    <apex:selectOptions value="{!subCategories}"/>
</apex:selectList>
</apex:actionRegion>
Related Topic