I haven't been able to find an answer to this as all the answers are somewhat different to what I'm trying to achieve.
Summary before giving the details:
- apex:selectList where the values are dynamically generated from the controller
- When the user clicks a button, I want the MULTIPLE (all the examples I've found are with one value)selected values to be passed to a List variable on the controller
- I'm not interested in passing the values every time they change, I want them to be passed when the button is clicked
- Optionally, when the button is clicked, I want the selected values to be displayed so that the user can confirm them.
Controller where the values are generated:
//the variable holding the selected values, supposedly
public List<String> typeMembers{get;set;}
//the available options
public List<SelectOption> getMembers(){
List<SelectOption> options = new List<SelectOption>();
for(String member : OrgMetadata.ListMetadata('CustomObject')){
options.add(new SelectOption(member,member));
}
return options;
}
Then, this is referenced in the markup:
<apex:selectList value="{!typeMembers}" multiselect="true" size="10" id="memberList">
<apex:selectOptions value="{!members}"/>
</apex:selectList>
Button to retrieve the selected values:
<apex:commandButton action="{!retrieveSelectedValues}" reRender="selectedValuesPanel" value="Select" status="status"/>
When I see the debug log, the method retrieveSelectedValues is not printing anything
public PageReference retrieveSelectedValues(){
System.debug('Selected Values: '+typeMembers);
return null;
}
I have tried the alternative approach, calling retrieveSelectedValues on the onChange attribute of the selectList itself
<apex:selectList value="{!typeMembers}" multiselect="true" size="10" id="memberList">
<apex:selectOptions value="{!members}"/>
<apex:actionSupport event="onchange" reRender="selectedValuesPanel" action="{!retrieveSelectedValues}" />
</apex:selectList>
Everytime I select a new value, retrieveSelectedValues is called, but the debug log doesn't show anything.
What am I missing?