Multiselect Picklists - El Toro - Find articles about Visualforce, Apex, and Salesforce in general

Print Preview

Multiselect Picklists

This sample demonstrates how to work with Multiselect picklists. Since you can select more than one option, the value is a list of string as demonstrated in this Visualforce page:

<apex:page controller="sampleCon">
        <apex:selectList value="{!countries}" multiselect="true">
            <apex:selectOptions value="{!items}"/>

        <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>

    <apex:outputPanel id="out">
        <apex:actionstatus id="status" startText="testing...">
            <apex:facet name="stop">
                    <p>You have selected:</p>
                    <apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>

and controller:

public class sampleCon {
	String[] countries = new String[]{};
	public PageReference test() {
		return null;
	public List<SelectOption> getItems() {
		List<SelectOption> options = new List<SelectOption>();
		options.add(new SelectOption('US','US'));
		options.add(new SelectOption('CANADA','Canada'));
		options.add(new SelectOption('MEXICO','Mexico'));
		return options;
	public String[] getCountries() {
		return countries;
	public void setCountries(String[] countries) {
		this.countries = countries;

comments powered by Disqus

© El Toro . IT @ 2013
Andrés Pérez