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
RoadieRoadie 

SelectOption Multiselect="false"

Hi, I'm having issues with the SelectList and setting multiselect to false. To test things out, I tried reverting back to the sample code listed in the cookbook (code below). The only thing (I think) that I changed is the multiselect="true" to multiselect="false" in the Visualforce code below. When the user selects a country and clicks the "Test" button, the name of the country is not displayed on the screen as it should. Also, the debug log shows the following: 
 
15:19:14 DEBUG - ***Begining Page Log for /apexpages/devmode/developerModeContainer.apexpj_id0:j_id1:j_id2: An error occurred when processing your submitted information.
 
Any thoughts? Thanks!
 
Code:
<apex:page controller="samplecon">
        <apex:form >
                <apex:selectList value="{!countries}" multiselect="false">
                        <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>

 
Code:
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;
        }
  
  }
VisualForceVisualForce
By default selectlist Multiselect is false..
 
       Problem in ur controller.If multiselect is false it returns only a single string not a array...
 
Code:
public class samplecon {
        String countries;
        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;
        }
  
  }

 
RoadieRoadie
Thanks so much!
SteveBowerSteveBower
I came across this as well.

Please add it to the documentation.

Thanks, Steve.
jlojlo
I ran in to the "An error occurred when processing your submitted information" message as well. It was because the code I was working on was trying to bind an inputText field to the Task "Subject" field which is a "combobox". If you run in to this error, make sure that the type of field you've placed on your Visualforce page is compatible with the field that you're binding it to.




yvk431yvk431

I observed this error mainly with SelectLists , where if in value attribute we didnt gave the appropriate value

like {!countries }, instead we should give it as {!countries.Id} or {!countries.Name}.

 

I have resolved my issue by making this change.

 

Cheers

LoserKidLoserKid

Thanks i was having this problem also and VF's post worked perfect. Please make it as the solution for others to use.

 

AK