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.