You need to sign in to do that
Don't have an account?
Apex SelectList - Default value problem
Hi
Can some one pls. let me know how to set the all valuses in multiselect Pick list as default. here is the code.
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('Americas','Americas'));
options.add(new SelectOption('AP','AP'));
options.add(new SelectOption('EMEA','EMEA'));
return options;
}
public String[] getCountries() {
return countries;
}
public void setCountries(String[] countries) {
this.countries = countries;
}
}
Page
-------------------------------------------------------
<apex:page controller="sampleCon">
<apex:form >
<apex:selectList value="{!countries}" multiselect="true"> Channel :
<apex:selectOptions value="{!items}"/>
</apex:selectList><p/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
<apex:outputPanel id="out">
<apex:actionstatus id="status" startText="testing...">
<apex:facet name="stop">
<apex:outputPanel >
<p>You have selected:</p>
<apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:page>
Thanks for your help in advance.
put it in your constructor i.e.
public sampleCon() {
this.countries.add('Americas');
this.countries.add('AP');
this.countries.add('EMEA');
}
All Answers
put it in your constructor i.e.
public sampleCon() {
this.countries.add('Americas');
this.countries.add('AP');
this.countries.add('EMEA');
}
Thanks tukmol !
It worked !