I am trying to bind a pick list from a controller, my goal is to get the IDs from User Object and display them in the pick list. Any help will be appreciate it!


 <apex:selectList value="{!param}" size="1"  >
     <apex:selectOption itemLabel="{!param}" itemValue="{!param}" />


  public List<User> param{
             return  param = [Select id from User ];


1 Answer 1


You can build the SelectOption objects in your controller:

public Id selectedUserId {get; set;}

public List<SelectOption> getUserSelectOptions() {
    List<SelectOption> options = new List<SelectOption>();
    for (User u : [Select Id, Name from User order by Name limit 1000]) {
        options.add(new SelectOption(u.Id, u.Name));
    return options;

and so the Visualforce becomes:

<apex:selectList value="{!selectedUserId}" size="1">
    <apex:selectOptions value="{!userSelectOptions}"/>

Note that the earlier version of this answer suggested using an apex:repeat to allow multiple apex:selectOption elements but as Carlos reports in his comment below Visualforce validates against that.


You must log in to answer this question.

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