1

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!

VF

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

Controller

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

        set;
  }

1 Answer 1

4

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}"/>
</apex:selectList>

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.

0

You must log in to answer this question.

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