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
Rick MacGuiganRick MacGuigan 

apex:selectList not showing selected items on Visual Force page

I am not getting any selectd options in the SelectOption list to show on my Visual Force page. Beow is the VF snippet and controller.

Example
public class sampleConSubmissions {
    
     String[] submissions = new String[]{};

    public sampleConSubmissions(ApexPages.StandardController controller) {

    }
        
            
        public PageReference test() {
            return null;
        }
            
        public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('TR00025712016 - Umbr only','TR00025712016 - Umbr only'));
            options.add(new SelectOption('TR00028982016 - Casualty','TR00028982016 - Casualty'));
            options.add(new SelectOption('TR18622016 - Casualty','TR18622016 - Casualty'));
            options.add(new SelectOption('TR20612016 - Property','TR20612016 - Property'));
            return options;
        }
            
        public String[] getsubmissions() {
            return submissions;
        }
            
        public void setsubmissions(String[] submissions) {
            this.submissions = submissions;
        }
    }
 
<apex:selectList value="{!submissions}" multiselect="true">
            <apex:selectOptions value="{!items}"/>
        </apex:selectList><p/>

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

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

 
Best Answer chosen by Rick MacGuigan
Lakshmi SLakshmi S
Hi Rick MacGuigan,


I think no errors in your code, you first enter the data in required fields and then select the values from list, then click on ' Select Submissions button' it shows the selected values.
See the below pic.
User-added image

If it solves your issue, select the best answer....

Regards
Narasimha.

 

All Answers

sujitha Ramachandrunisujitha Ramachandruni
Hi
Try this
Apex code:
public class sampleConSubmissions {

 public String submissions { get; set; }

    public PageReference test() {
        return null;
    }


    public List<SelectOption> getItems() {
    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('TR00025712016 - Umbr only','TR00025712016 - Umbr only'));
    options.add(new SelectOption('TR00028982016 - Casualty','TR00028982016 - Casualty'));
    options.add(new SelectOption('TR18622016 - Casualty','TR18622016 - Casualty'));
    options.add(new SelectOption('TR20612016 - Property','TR20612016 - Property'));
        return options;
    }


   
}

vf page
<apex:page controller="sampleConSubmissions">
 <apex:form >

<apex:selectList value="{!submissions}" multiselect="true">

                <apex:selectOptions value="{!items}"/>
 </apex:selectlist>
 
 <apex:commandButton value="Select Submissions" action="{!test}" rerender="out" status="status"/>
 
 
 <apex:outputPanel id="out">
 <apex:actionstatus id="status" startText="testing...">
 <apex:facet name="stop">
 <apex:outputPanel >
 <p>You have selected:</p>
 <apex:dataList value="{!submissions}" var="c">{!c}</apex:dataList>
 
 </apex:outputpanel>
 
 </apex:facet>
 
 </apex:actionstatus>
 </apex:outputpanel>
 </apex:form>
</apex:page>
Lakshmi SLakshmi S
HI Rick,

Change your code..

------VF Page-------

<apex:page controller="sampleConSubmissions" >
    <apex:form>
    <apex:selectList value="{!submissions}" multiselect="true">
            <apex:selectOptions value="{!items}"/>
        </apex:selectList><p/>

        <apex:commandButton value="Select Submissions" 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="{!submissions}" var="c">{!c}</apex:dataList>
                </apex:outputPanel>
            </apex:facet>
        </apex:actionstatus>
    </apex:outputPanel>
</apex:page>


----Apex Class ----

public class sampleConSubmissions {
    
     String[] submissions = new String[]{};
    
        public PageReference test() {
            return null;
        }
            
        public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('TR00025712016 - Umbr only','TR00025712016 - Umbr only'));
            options.add(new SelectOption('TR00028982016 - Casualty','TR00028982016 - Casualty'));
            options.add(new SelectOption('TR18622016 - Casualty','TR18622016 - Casualty'));
            options.add(new SelectOption('TR20612016 - Property','TR20612016 - Property'));
            return options;
        }
            
        public String[] getsubmissions() {
            return submissions;
        }
            
        public void setsubmissions(String[] submissions) {
            this.submissions = submissions;
        }
    }



VF Page output:
---------------
output
Rick MacGuiganRick MacGuigan
Thanks sujitha and Lakshmi  for the relpies. Used your code and I still can't get this results to display. Here is the full VF page. Note that I'm using an extended controller. I'm able to select options but the display of the selected option is not showing. 
 
<apex:page standardController="Account_Summary__c" readOnly="false" extensions="sampleConSubmissions" >

<!-------------------------------------------------->
<!--Contoller Information variables --> 
<!-- declare variable for Parent Audit ID dependency to SOQL field in controller. --> 
<apex:variable var="AcctID" value="{!Account_Summary__c.Name}" />
<!-- <apex:variable var="SampleID" value="{!Auto_Drivers__c.Auto_Audit_Sample_Policy__c}" /> -->

<!-- <apex:variable var="a" value="{!audit}" /> -->
<apex:variable var="acctsum" value="{!Account_Summary__c}" />

<!--Account Summary control variables -->
<apex:variable var="BestRating" value="{!acctsum.BestRating__c}" />

<!-------------------------------------------------->

<apex:form id="form1">
<apex:sectionHeader title="New (VF) Account Summary" subtitle="Account Summary" help="{!$Resource.Help_MaidenReUWGuidelines}"/>

<apex:pageBlock id="block1" title="Account Summary - General Information" >

<apex:outputPanel layout="none" rendered="true" >
<b>Sample Ref:</b> &nbsp;  <apex:outputField value="{!Account_Summary__c.Name}"  /> 
</apex:outputPanel> 


<p><b>Hello {!$User.FirstName}!</b> &nbsp; <font color='blue'> Enter Account Summary information below. </font> </p>
<!-- automate helper text for potential user instruction --> 
  <apex:outputText style="font-style:italic;background-color:yellow;color:blue" value="sample instruction text ??" />

<!-- enable display of messages for all conditions --> 
<apex:messages title="data incorrectly entered." style="background-color:yellow; color: red" /> 

<apex:pageBlockButtons >
<apex:commandButton value="Save Only" action="{!Save}"/> 
</apex:pageBlockButtons>

</apex:pageBlockSection>

<!-- script used to collapse sections initially. Otherwise they do not trigger event -->
<script>twistSection(document.getElementById("{!$Component.testsection1}").childNodes[0].childNodes[0]); </script>

<!-- GENERAL INFORMATION -->

 <apex:pageBlockSection columns="1" id="section1" title="General Information" showHeader="false" >
 
 <!-- setting required='true' will bypass field validation if field is not rendered -->
 
 <apex:inputField value="{!Account_Summary__c.Name}" required="true" />
 <apex:inputField value="{!Account_Summary__c.Program_Name__c}" required="true"  >
     <apex:actionSupport event="onchange" reRender="section1" />
     </apex:inputField>  
 <apex:inputField value="{!Account_Summary__c.Report_Status__c}"  />
       
 
 
 <apex:actionRegion >
 <apex:pageBlockSection columns="1" showHeader="false"  >
 <apex:inputField value="{!Account_Summary__c.Lines_of_Business__c}" >
    <apex:actionSupport event="onchange" reRender="LOB" />
    </apex:inputField>
 </apex:pageBlockSection> 
 </apex:actionRegion>   
     
 <apex:outputPanel id="LOB">
 <apex:pageBlockSection columns="1" showHeader="false"  >           
 <apex:inputField value="{!Account_Summary__c.Other_Line_of_Business__c}"  style="color:blue;" rendered="{!CONTAINS(Account_Summary__c.Lines_of_Business__c,'Other')}" /> 
 </apex:pageBlockSection>
 </apex:outputPanel>


</apex:pageBlockSection>
<!-- script used to collapse sections initially. Otherwise they do not trigger event -->
<script>twistSection(document.getElementById("{!$Component.testsection1}").childNodes[0].childNodes[0]); </script>


<!-- SUBMISSION INFORMATION -->
 <apex:pageBlockSection columns="1" id="section2" title="Submission Information" showHeader="true" >
  <!-- automate helper text for potential user instruction --> 
  <apex:outputText style="font-style:italic;background-color:yellow;color:blue" value="sample instruction text ??" />

<!-------------------------------------------------->
    <apex:selectList value="{!submissions}" multiselect="true">
            <apex:selectOptions value="{!items}"/>
        </apex:selectList><p/>

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

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


 </apex:pageBlockSection>
 
<!-- POST BINDING INFORMATION -->
 <apex:pageBlockSection columns="1" id="section3" title="Post Binding Information (black box)" showHeader="true" >
  <!-- automate helper text for potential user instruction --> 
  <apex:outputText style="font-style:italic;background-color:yellow;color:blue" value="sample instruction text ??" />

 </apex:pageBlockSection> 
 
 
<!-------------------------------------------------->
</apex:pageBlock>
</apex:form>

<apex:relatedList list="AttachedContentNotes" />
<apex:relatedList list="AttachedContentDocuments" />


</apex:page>

Controller: 
 
public class sampleConSubmissions {
    
     String[] submissions = new String[]{};

    public sampleConSubmissions(ApexPages.StandardController controller) {

    }
        
            
        public PageReference test() {
            return null;
        }
            
        public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('TR00025712016 - Umbr only','TR00025712016 - Umbr only'));
            options.add(new SelectOption('TR00028982016 - Casualty','TR00028982016 - Casualty'));
            options.add(new SelectOption('TR18622016 - Casualty','TR18622016 - Casualty'));
            options.add(new SelectOption('TR20612016 - Property','TR20612016 - Property'));
            return options;
        }
            
        public String[] getsubmissions() {
            return submissions;
        }
            
        public void setsubmissions(String[] submissions) {
            this.submissions = submissions;
        }
    }


 
Lakshmi SLakshmi S
Hi Rick MacGuigan,


I think no errors in your code, you first enter the data in required fields and then select the values from list, then click on ' Select Submissions button' it shows the selected values.
See the below pic.
User-added image

If it solves your issue, select the best answer....

Regards
Narasimha.

 
This was selected as the best answer
Rick MacGuiganRick MacGuigan
Narasimha - thanks. Totally overlooked the required fields.