function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Assigning values of a select list to a List object in the controller



In my VisualForce page i have a select list whose values i want to pass to my Controller when the command button is pressed.

The select list  is defined as follows :


 <apex:selectList id="member_list" value="{!selectedMembers}" size="10" >
                 <apex:selectOptions value="{!memberNames}"/>

 The command button is defined as follows :


<apex:commandButton value="Save" action="{!move}" rerender="hiddenBlock">
              <apex:param name="selected" 

<apex:pageBlock id="hiddenBlock" rendered="false"></apex:pageBlock>

If im not mistaken, {!selectedMembers } is the set of all values in my select list.

Now, in my controller, how to define {!selectedOptions} as List <String> object ?


Please help

Thank You.







Define a list of the type of the members which i guess is String

public List<String> selected = new List<String>();



Thanks for the reply imuino.In my controller, i now have :



public List<String> selectedOptions = new List<String>();


But im getting the following error  .


Invalid conversion from runtime type LIST:String to LIST:System.SelectOption


FYI, the select list gets populated from the AccountContactRole table, but

public List<AccountContactRole> selectedOptions = new List<AccountContactRole>();

does not work either.


Where am i going wrong ?


Please help.


Invalid conversion from runtime type LIST:String to LIST:System.SelectOption

Use List<SelectOption> instead of List<string>


I mean your apex class should contain the following method


public List<SelectOption> getmemberNames()
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption ('A', '1'));
options.add(new SelectOption ('B', '2'));
return options;


and then define the get set methods for selectedMembers as follows


public void setselectedMembers(List<SelectOption> sops)

selectedmembers = sops;
public List<SelectOption> getselectedMembers()
return selectedMembers;