0

I have a selectoption and I am trying to pass the value of the itemValue attribute to the standardsetcontroller in order to return query results based on the itemValue. I have the default selection set to 'e' which returns the expected result. But when a different selectOption value is selected, the page doesn't reRender to produce the new resultset based on the change. Below is my apex and visualforce markup :

public with sharing class cases {

// Variables required for Sorting.
    public String temp {get; set;}
    public list<case> temp1 {get; set;}
    public id uid;
    public id creator;
    public id actid;    
    public String soql {get;set;}
    public List <case> caseList1 = New List <case>();

public List <case> caseList2 = New List <case>();

// Constructor 
public cases(){
    this.uid = UserInfo.getUserid();
    this.actid = [select accountid from user where id = :uid][0].accountid;

     if (temp != null){
         this.temp = temp;
         System.debug('selected temp is :' + this.temp);
     }else{ 
        this.temp = 'e';
    }

    getCaseList2();


}

            public pageReference getCaseList2(){
                  this.temp = temp;
                  getCaseList();
                  return null;
            }   


            // Method for list display
            public List<case> getCaseList() {

                return con.getRecords();
            }

            // instantiate the StandardSetController from a query locator
            public ApexPages.StandardSetController con {
                get {

                                            if(con == null && this.temp == 'a') {
                                                            // String Query to have a list of cases for a respective End-user.
                                                            soql = ''+ 'SELECT'+ ' CreatedById,' + ' AccountId,' + ' OwnerId,' + ' Id,' + ' CaseNumber,' + ' CreatedDate,' + ' Requested_By__c,' + ' Subject,' + ' Release_Type__c,' + ' Status,' + ' Priority,' + ' Major_Release_Version__c,' + ' type' + ' From Case';
                                                            System.debug('temp a is: ' + temp);
                                                            // Passing the String array to a list with Selected field sorting.
                                                            caseList1 = Database.query(soql + ' AccountId = :actid and status = \'Closed\' ' ); 

                                                            // setting values of List in StandardSetController.
                                                            con = new ApexPages.StandardSetController(caseList1);
                                                            system.debug(con);
                                                            // sets the number of records in each page set
                                                            con.setPageSize(20);
                                            }
                                            else if(con == null && temp == 'b') {
                                                            // String Query to have a list of cases for a respective End-user.
                                                            soql = ''+ 'SELECT'+ ' CreatedById,' + ' AccountId,' + ' OwnerId,' + ' Id,' + ' CaseNumber,' + ' CreatedDate,' + ' Requested_By__c,' + ' Subject,' + ' Release_Type__c,' + ' Status,' + ' Priority,' + ' Major_Release_Version__c,' + ' type' + ' From Case';
                                                            System.debug('temp b is: ' + temp);
                                                            // Passing the String array to a list with Selected field sorting.
                                                            caseList1 = Database.query(soql + ' AccountId = :actid and status != \'Closed\' '); 

                                                            // setting values of List in StandardSetController.
                                                            con = new ApexPages.StandardSetController(caseList1);

                                                            // sets the number of records in each page set
                                                            con.setPageSize(20);

                                                            }else if(con == null && temp == 'e') {
                                                            // String Query to have a list of cases for a respective End-user.
                                                            soql = ''+ 'SELECT'+ ' CreatedById,' + ' AccountId,' + ' OwnerId,' + ' Id,' + ' CaseNumber,' + ' CreatedDate,' + ' Requested_By__c,' + ' Subject,' + ' Release_Type__c,' + ' Status,' + ' Priority,' + ' Major_Release_Version__c,' + ' type' + ' From Case';
                                                            System.debug('temp e is: ' + temp);
                                                            // Passing the String array to a list with Selected field sorting.
                                                            caseList1 = Database.query(soql + ' order by ' + sortField + ' ' + sortDir ); 

                                                            // setting values of List in StandardSetController.
                                                            con = new ApexPages.StandardSetController(caseList1);

                                                            // sets the number of records in each page set
                                                            con.setPageSize(20);
                                            }
                                            return con;
        }
        set;
    }
} 

Visualforce markup

 <apex:page controller="cases"> 

    <apex:form id="form">
    <apex:selectList id="selected_list" value="{!temp}" required="false" size="1">
        <apex:selectOption itemvalue="a" itemLabel="All Closed Cases"/>
        <apex:selectOption itemvalue="b" itemLabel="All Open Case"/>            
        <apex:selectOption itemvalue="e" itemLabel="Recently Viewed Cases" />
        <apex:actionSupport event="onchange" reRender="pgblock" action="{!getCaseList2}" oncomplete="getCaseList2();">

        </apex:actionSupport>
    </apex:selectList>

<apex:pageBlock id="pgblock" >
    <apex:pageBlockSection title="Case Details
        <apex:pageBlockTable value="{!CaseList}" var="CaseList" >

                <apex:column >
                    <apex:facet name="header">
                       <apex:commandLink value="Case Number" action="{!toggleSort}" rerender="pgblock">

                            <apex:param name="sortField" value="CaseNumber" assignTo="{!sortField}"/>
                       </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!CaseList.CaseNumber}"/>
                </apex:column> 


                <apex:column >
                    <apex:facet name="header">
                       <apex:commandLink value="Created Date" action="{!toggleSort}" rerender="pgblock">

                            <apex:param name="sortField" value="CreatedDate" assignTo="{!sortField}"/>
                       </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!CaseList.CreatedDate}"/>
                </apex:column> 
    </apex:pageBlockTable>
</apex:pageBlockSection>
</apex:form>

Thanks for any suggestions.

2
  • how/ where are you filtering based on select list option/ all I can see from you soql string is that you are choosing same fields for all the select option values. Are you able to see the correct select option value you choose from the page from your system debug?
    – Rao
    Commented Jun 23, 2014 at 17:58
  • @rao - I set the default as 'e' in the constructor but I'm am filtering based on the value that is returned by the selectoption. But when I check the logs it doesn't seem to be returning the selectoption value to the standardsetcontroller. Commented Jun 23, 2014 at 18:03

2 Answers 2

1

Change you page to :

<apex:page controller="cases"> 

    <apex:form id="form">
    <apex:selectList id="selected_list" value="{!temp}" required="false" size="1">
        <apex:selectOptions value="{!items}"/>
    </apex:selectList>

<apex:pageBlock id="pgblock" >
    <apex:pageBlockSection title="Case Details
        <apex:pageBlockTable value="{!CaseList}" var="CaseList" >

                <apex:column >
                    <apex:facet name="header">
                       <apex:commandLink value="Case Number" action="{!toggleSort}" rerender="pgblock">

                            <apex:param name="sortField" value="CaseNumber" assignTo="{!sortField}"/>
                       </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!CaseList.CaseNumber}"/>
                </apex:column> 


                <apex:column >
                    <apex:facet name="header">
                       <apex:commandLink value="Created Date" action="{!toggleSort}" rerender="pgblock">

                            <apex:param name="sortField" value="CreatedDate" assignTo="{!sortField}"/>
                       </apex:commandLink>
                    </apex:facet>
                    <apex:outputField value="{!CaseList.CreatedDate}"/>
                </apex:column> 
    </apex:pageBlockTable>
</apex:pageBlockSection>
</apex:form>

Controller: When you see the system.debug statements you should the temp value to be the value you choose. Adjust your SOQL accordingly in the code.

public with sharing class cases {

// Variables required for Sorting.
    public String temp {get; set;}
    public list<case> temp1 {get; set;}
    public id uid;
    public id creator;
    public id actid;    
    public String soql {get;set;}
    public List <case> caseList1 = New List <case>();
public List <case> caseList2 = New List <case>();

// Constructor 
public cases(){
    this.uid = UserInfo.getUserid();
    this.actid = [select accountid from user where id = :uid][0].accountid;
    getCaseList2();
}
            public List<SelectOption> getItems() {
                List<SelectOption> options = new List<SelectOption>();
                options.add(new SelectOption('a','a'));
                options.add(new SelectOption('b','b'));
                options.add(new SelectOption('c','c'));
            return options;
            }           
            public pageReference getCaseList2(){
                  this.temp = temp;
                  getCaseList();
                  return null;
            }   


            // Method for list display
            public List<case> getCaseList() {

                return con.getRecords();
            }

            // instantiate the StandardSetController from a query locator
            public ApexPages.StandardSetController con {
                get {

                                            if(con == null && this.temp == 'a') {
                                                            // String Query to have a list of cases for a respective End-user.
                                                            soql = ''+ 'SELECT'+ ' CreatedById,' + ' AccountId,' + ' OwnerId,' + ' Id,' + ' CaseNumber,' + ' CreatedDate,' + ' Requested_By__c,' + ' Subject,' + ' Release_Type__c,' + ' Status,' + ' Priority,' + ' Major_Release_Version__c,' + ' type' + ' From Case';
                                                            System.debug('temp a is: ' + temp);
                                                            // Passing the String array to a list with Selected field sorting.
                                                            caseList1 = Database.query(soql + ' AccountId = :actid and status = \'Closed\' ' ); 

                                                            // setting values of List in StandardSetController.
                                                            con = new ApexPages.StandardSetController(caseList1);
                                                            system.debug(con);
                                                            // sets the number of records in each page set
                                                            con.setPageSize(20);
                                            }
                                            else if(con == null && temp == 'b') {
                                                            // String Query to have a list of cases for a respective End-user.
                                                            soql = ''+ 'SELECT'+ ' CreatedById,' + ' AccountId,' + ' OwnerId,' + ' Id,' + ' CaseNumber,' + ' CreatedDate,' + ' Requested_By__c,' + ' Subject,' + ' Release_Type__c,' + ' Status,' + ' Priority,' + ' Major_Release_Version__c,' + ' type' + ' From Case';
                                                            System.debug('temp b is: ' + temp);
                                                            // Passing the String array to a list with Selected field sorting.
                                                            caseList1 = Database.query(soql + ' AccountId = :actid and status != \'Closed\' '); 

                                                            // setting values of List in StandardSetController.
                                                            con = new ApexPages.StandardSetController(caseList1);

                                                            // sets the number of records in each page set
                                                            con.setPageSize(20);

                                                            }else if(con == null && temp == 'e') {
                                                            // String Query to have a list of cases for a respective End-user.
                                                            soql = ''+ 'SELECT'+ ' CreatedById,' + ' AccountId,' + ' OwnerId,' + ' Id,' + ' CaseNumber,' + ' CreatedDate,' + ' Requested_By__c,' + ' Subject,' + ' Release_Type__c,' + ' Status,' + ' Priority,' + ' Major_Release_Version__c,' + ' type' + ' From Case';
                                                            System.debug('temp e is: ' + temp);
                                                            // Passing the String array to a list with Selected field sorting.
                                                            caseList1 = Database.query(soql + ' order by ' + sortField + ' ' + sortDir ); 

                                                            // setting values of List in StandardSetController.
                                                            con = new ApexPages.StandardSetController(caseList1);

                                                            // sets the number of records in each page set
                                                            con.setPageSize(20);
                                            }
                                            return con;
        }
        set;
    }
} 
0

I finally discovered what the issue was with my code. There was no reason for me to check for "if (con == null) as when the page loads it already displays the values based on the default selectoption. Hence I only needed to check for the value of "temp".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .