0

I have a vf page where i have country(picklist> and geography(mutiselect list). When i am selecting from Country, nothing is getting populated in the geography list box. Please let me know where i am doing wrong.

Apex Class -

public class ControllerExtension2 {

public string model{get;set;}
public List<String> SelectedDept{get;set;}
public List<Geography__c> results{get;set;}
public List<SelectOption> AllDept{get;set;}
public List<SelectOption> AllName{get;set;}
public List<String> SelectedName{get;set;}

public ControllerExtension2 (){

AllDept= new List<SelectOption>();
AllDept= getDept();
AllName= new List<SelectOption>();
AllName= getName();
}

 public List<SelectOption> getDept()
    {
        List<SelectOption> options = new List<SelectOption>();
        Schema.DescribeFieldResult departfield =  RFP__c.Country__c.getDescribe();
        List<Schema.PicklistEntry> picklist = departfield.getPicklistValues();
        for( Schema.PicklistEntry f : picklist){      
        options.add(new SelectOption(f.getLabel(), f.getValue()));
        }    
        return options;

     }

       public List<SelectOption> getName()
    {
        List<SelectOption> options = new List<SelectOption>();
        Set<String> sProj = new Set<String>();

        if(SelectedDept != null && SelectedDept.size()>0)
            {
               for(String oSelectOption : SelectedDept)
               {
                    sProj.add(oSelectOption);
               }
               for(Geography__c Proj  :[select Id, Canonical_Name__c, Type__c from Geography__c where status__c = 'active' AND country__c IN : sProj  order by Canonical_Name__c] )
               {
                    options.add(new SelectOption(Proj.ID,Proj.Canonical_Name__c));
               }

            }

        return options;

     }

   public void FindAllName()
    {
        //AllName= new List<SelectOption>();
        AllName= getName();
    }  

}

VF Page -

<apex:page controller="ControllerExtension2">
<apex:form id="theForm">
<apex:pageBlock id="theFilterPageBlock">
 <apex:panelGroup >
                                <apex:panelGrid columns="2">

                                    <apex:outputLabel value="Country" for="DPList" style="font-weight:bold;margin-left:145px;"></apex:outputLabel>
                                     <apex:selectList value="{!SelectedDept}" multiselect="false" title="Department" id="DPList" size="1" style="min-width:300px;width:auto;margin-left:12px;" >
                                   <apex:actionSupport event="onchange" action="{!FindAllName}" reRender="theForm" status="actStatusId">

                                        </apex:actionSupport>
                                       <apex:selectOptions value="{!AllDept}" ></apex:selectOptions> 
                                    </apex:selectList>
                                </apex:panelGrid>
                        </apex:panelGroup>


                        <apex:panelGroup >
                                <apex:panelGrid columns="2">

                                    <apex:outputLabel value="Geography" for="NameList" style="font-weight:bold;margin-left:40px;"></apex:outputLabel>
                                     <apex:selectList value="{!SelectedName}" multiselect="true" title="ProjName" id="NameList" size="6" style="min-width:300px;width:auto;margin-left:12px;" >
                                       <apex:selectOptions value="{!AllName}" ></apex:selectOptions>
                                    </apex:selectList>

                                </apex:panelGrid>

                        </apex:panelGroup>   
</apex:pageBlock>
</apex:form>
</apex:page>
3
  • Try changing the <apex:actionSupport rerender="theForm" /> to rerender the second picklist, instead of the whole form. It may also be a good idea to make sure that the event you are trying to catch to update the form is firing correctly. Commented Sep 24, 2015 at 17:13
  • Hi Battery.cord.. If i change size="1" to size="6".. It is working fine.. <apex:selectList value="{!SelectedDept}" multiselect="false" title="Department" id="DPList" size="1" style="min-width:300px;width:auto;margin-left:12px;" > Commented Sep 24, 2015 at 17:16
  • But i need country to be a picklist not a multiselectlist..Can u check plzz. Commented Sep 24, 2015 at 17:17

1 Answer 1

2

Here is what I think is your issue:

<apex:selectList value="{!SelectedDept}" multiselect="false" title="Department" id="DPList" size="1" style="min-width:300px;width:auto;margin-left:12px;" >

is bound to Apex controller variable

public List<String> SelectedDept{get;set;}

yet, when using a selectList component where multiselectList is false, you need to bind to a controller variable of type String, not List<String>

From the doc, value:

A merge field that references the controller class variable that is associated with this selectList. For example, if the name of the associated variable in the controller class is myListSelections, use value="{!myListSelections}" to reference the variable. If multiselect is true, the value attribute must be of type String[] or a List of strings. Otherwise, it must be of type String.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .