1

I've been over the code a thousand times but cannot work out why the getVenueLst() method is not populating the SelectList on the vf page. Anyone have any ideas?

Controller

Public string selectedVenue {get;set;}
Public List<Selectoption> VenueLst {get;set;}

Public List<SelectOption> getVenueLst(){
  List<SelectOption> venueoptions = new List<SelectOption>();
      venueoptions.add(new SelectOption('All','All'));
      for(Training_Venue__c ven : [select name from Training_Venue__c order by name])
        {
        venueoptions.add(new SelectOption(string.valueOf(ven), string.valueOf(ven)));
        system.debug('Venue to add to SelectOption is '+ven);
        }
      return venueoptions;
    }

VF Page

<div id="venueselect">
    <outputText>Venue Filter: </outputText>

    <apex:selectList value="{!selectedVenue}" style="width:220px" size="1" id="venue">
         <apex:selectOptions value="{!VenueLst}"/>
    </apex:selectList>
</div>

The page and controller have additional code but it shouldnt cause this not to work.

2 Answers 2

3

reason of this because you have field properties {get; set;} and getter getVenueLst at same time. Choose one.


Priority is the following, when field is referencing on VF page:

  1. looking for property name made public with get; (you are here, that is why nothing is populated for SelectOption list)
  2. if no such property, looking for public method which matched get'PropertyName'

I prefer lazy loading in such cases:

public String selectedVenue {get; set;}
public List<SelectOption> venueLst {
    get{
        if(venueLst == null){
            venueLst = loadVenueLst();
        }
        return venueLst;
    }
    set;
    }

private List<SelectOption> loadVenueLst(){
    List<SelectOption> venueoptions = new List<SelectOption>();
    venueoptions.add(new SelectOption('All','All'));
    for(Training_Venue__c ven : [select name from Training_Venue__c order by name]){
        venueoptions.add(new SelectOption(string.valueOf(ven), string.valueOf(ven)));
        system.debug('Venue to add to SelectOption is '+ven);
    }
    return venueoptions;
}
0
-1

Controller:


public String selectedRecordId {get; set;}    // to get value from Vf-Page

public List<SelectOption> getRecords() {
    List<SelectOption> lstOptions = new List<SelectOption>();
    lstOptions.add(new SelectOption('Please Select','Please Select'));   // to show as default 
    List<obj_Name> lst1 = [select Id, Name from obj_Name];
    for(obj_Name : lst1 ){
        lstOptions.add(new SelectOption(obj_Name.Id, obj_Name.Name));
    }
    system.debug(lstOptions);
    return lstOptions;
}

VF-Page:

 <apex:pageBlockSection title="Title" columns="2">
<apex:selectList label="Select Property" id="RecordId" value="{!selectedRecordId}" size="1">
     <apex:selectOptions value="{!records}" />
     <apex:actionSupport event="onchange" reRender="leadStatus" />
</apex:selectList>
 </apex:pageBlockSection>

This works for me.

1
  • 1
    Code dump answers are discouraged. If your code helps the Original Poster, please take a moment to edit your Answer to add some description that explains what you changed and how it helps.
    – Adrian Larson
    Commented Oct 31, 2022 at 11:36

You must log in to answer this question.

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