function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

SelectList and actionFunction confusion

i have create an apex class

public class sampleCon {
public PageReference setFieldApiName() {
System.debug('field are '+ Apexpages.currentPage().getParameters().get('fieldName'));
return null;
String[] countries = new String[]{};

public PageReference test() {
return null;

public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
return options;

public String[] getCountries() {
return countries;

public void setCountries(String[] countries) {
this.countries = countries;


and my visualforce page is 


<apex:page controller="sampleCon">
        <apex:selectList value="{!countries}"  multiselect="true" onchange="setFieldApiName({! countries})"> <apex:selectOptions value="{!items}"/> </apex:selectList><p/> </apex:form> <apex:outputPanel id="out"> <apex:actionstatus id="status" startText="testing..."> <apex:facet name="stop"> <apex:outputPanel> <p>You have selected:</p> <apex:dataList value="{!countries}" var="c">{!c}</apex:dataList> </apex:outputPanel> </apex:facet> </apex:actionstatus> </apex:outputPanel> <apex:form> <apex:actionRegion > <apex:actionFunction name="setFieldApiName" action="{!setFieldApiName}" reRender="out"> <apex:param value="" name="fieldName"/> </apex:actionFunction> </apex:actionRegion> </apex:form> </apex:page>


when i select an item from the list and actionFunction will be called and from which there is a call to apex class function setFieldApiName i am expecting that country which i selected in debug but getting "field are null" .how to get the country value when it is changed in list please some one explain



i could not understood your question.u r asking how to create dropdownlist using custom controller?

<apex:page controller="sampleCon">
<apex:form id="form">
<apex:selectList value="{!countries}" multiselect="true">
<apex:selectOptions value="{!items}"/>
<apex:actionSupport event="onchange" action="{!setfieldapiname}" reRender="form"/>

This is really all you're looking for. In fact, this probably isn't even necessary; since whatever else you might use Countries for should automatically see the new values by virtue of the getters and setters.


Some notes here:


* Don't use more than one form. It's just a bad idea.

* Calling a JavaScript function for an attribute like that will always call the previous version of the values, because it won't be refreshed until after the actionFunction has been called, which is why your list is always wrong.


Not sure what you're hoping to accomplish, but hopefully my advice will help you out.