Multi-row: Wrapper class with multi-select picklists - El Toro - Find articles about Visualforce, Apex, Force.com and Salesforce in general

Print Preview

Multi-row: Wrapper class with multi-select picklists

<apex:page controller="aaPage78">
    <apex:form>
        <apex:outputPanel id="out">
            <table border="1">
                <apex:repeat value="{!Lists}" var="l">
                    <tr>
                        <td>
                            <apex:selectList value="{!l.countries}" multiselect="true">
                                <apex:selectOptions value="{!l.items}"/>
                            </apex:selectList><p/>
                        </td>
                        <td>
                            <apex:actionstatus id="status" startText="testing...">
                                <apex:facet name="stop">
                                    <apex:outputPanel>
                                        <p>You have selected:</p>
                                        <apex:dataList value="{!l.countries}" var="c">{!c}</apex:dataList>
                                    </apex:outputPanel>
                                </apex:facet>
                            </apex:actionstatus>
                        </td>
                    </tr>
                </apex:repeat>
            </table>
        </apex:outputPanel>
        <apex:commandButton value="Test" action="{!test}" status="status"/>
    </apex:form>
</apex:page>

public class aaPage78 {
    public List<selectList> lists {get; set;}

    public aaPage78() {
        lists = new List<selectList>();
        for (Integer i = 0; i < 5; i++) {
            lists.add(new selectList(i));
        }
    }

    public PageReference test() {
        return null;
    }

    public class selectList {
        Integer intValue;
        String[] countries = new String[]{};

        public selectList(Integer intValue) {
            this.intValue = intValue;
        }
        public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('Value:' + intValue + ' - US','Label:' + intValue + ' - US'));
            options.add(new SelectOption('Value:' + intValue + ' - CANADA','Label:' + intValue + ' - Canada'));
            options.add(new SelectOption('Value:' + intValue + ' - MEXICO','Label:' + intValue + ' - 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