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
louisa barrett 7louisa barrett 7 

Pass selectlist value bask to controller

i wonder if someone could help me please.
My Filter list is being populated, but I'm not sure how you pass the value of the SelectList value back to the controller, so the results are filtered appropriately.
I've looked at a lot of examples and they all have a Get;Set property for he value but I cannot see on any of them where that is actually being set.

Apex Code:

public with sharing class ChildOpportunitiesAP {
    private id Parent_Acc_Id;
    private string selectedValue;
    Public Integer noOfRecords{Get;Set;}
    Public Integer size {get;Set;}
    public String selectListValue{get;Set;}
    
          public ApexPages.StandardSetController controller {
                    get{
                 Parent_Acc_Id = ApexPages.currentPage().getparameters().get('id');
                        if(controller == null){
                            size = 4;
                            string queryString = 'SELECT Account.Name, Name, Total_Opportunity_Amount__c ' +
                                ' FROM Opportunity WHERE Account.Parent.id=: Parent_Acc_Id';
                                 controller = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                        controller.setPageSize(size);
                            noOfRecords = controller.getResultSize();
             }
             return controller;                              
            }set;
        }
    
         public List<Opportunity> getRelatedOpportunities(){
                        List <Opportunity> childOpps = New List<Opportunity>();
        FOR(Opportunity opp:(List<Opportunity>)controller.getRecords())
            childOpps.add(opp);
                 Return childOpps;   
         }
    
        public pageReference refresh(){
            controller = null;
            getRelatedOpportunities();
            controller.setPageNumber(1);
            return null;
        }  
    
    public List<selectOption> getAvailableFilters(){
        List<selectOption> options = new List<SelectOption>();
        List<Opportunity> availableOpps = new List<Opportunity>();
        availableOpps = [SELECT Account.Name, Name, Total_Opportunity_Amount__c FROM Opportunity WHERE Account.Parent.id=: Parent_Acc_Id];
        FOR(Opportunity opp: availableOpps)
        {
           options.add(new SelectOption(opp.Account.name, opp.account.name));
        }
       
        return options;
    }
    }


VF Page:
<apex:page sidebar="false" showHeader="false" Controller="ChildOpportunitiesAP">
   <apex:form >
          <apex:pageBlock title="Linked child opportunities" id="pb"> 
              Filter:
              <apex:selectList value="{! selectListValue }" size="1">
                  <apex:selectOptions value="{!availableFilters}"/>
                  <apex:actionSupport event="onchange" reRender="pb"/>
              </apex:selectList>
          <apex:pageBlockTable value="{! RelatedOpportunities}" var="opp">
              <apex:column value="{! opp.Account.Name}"/>
              <apex:column value="{! opp.Name}"/>
              <apex:column value="{! opp.Total_Opportunity_Amount__c}"/>
          </apex:pageBlockTable>
        <apex:panelGrid columns="7">
                <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!controller.first}" disabled="{!!controller.hasPrevious}" title="First Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!controller.previous}" disabled="{!!controller.hasPrevious}" title="Previous Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!controller.next}" disabled="{!!controller.hasNext}" title="Next Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!controller.last}" disabled="{!!controller.hasNext}" title="Last Page"/>
                <apex:outputText >{!(controller.pageNumber * size)+1-size}-{!IF((controller.pageNumber * size)>noOfRecords, noOfRecords,(controller.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
                <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
                </apex:outputPanel>
            </apex:panelGrid>
    </apex:pageBlock>
  </apex:form>
</apex:page>

What I also don't understand is why I can't filter the list directly, or cycle through the relatedOpportunities method as that already contains the relavant results, rather than having to hit the DB again.
So something like:
 FOR(Opportunity opp: getRelatedOpportunities)
        {
           options.add(new SelectOption(opp.Account.name, opp.account.name));
        }

Many thanks for any help
       

 
Best Answer chosen by louisa barrett 7
InfuInfu
Hi louisa barrett 7,

 <apex:actionSupport event="onchange"  action="{!method}"  reRender="pb"/>