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.

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;
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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