I'm trying to add a filter to my VisualForce page, with the following code:

VisualForce Code:

<apex:page controller="CaseController" sidebar="true">
<apex:form id="frm">

 <apex:selectList size="1" value="{!getcasetype}" >
     <apex:selectOptions value="{!casestatus}"> </apex:selectOptions>
     <apex:actionSupport event="onchange" action="{!displaycaselist}"/>

 <apex:outputLabel id="pnl1" >

     <apex:pageBlock >

         <apex:pageBlockTable value="{!caselst}" var="c">

             <apex:column headerValue="Case Number">
                 <apex:outputLink value="/{!c.id}"><apex:outputText value="{!c.CaseNumber}" /></apex:outputLink>

             <apex:column value="{!c.Contact.Name}"/>
             <apex:column value="{!c.Days_Open__c}"/>
             <apex:column value="{!c.Subject}"/>
             <apex:column value="{!c.Status}"/>
             <apex:column value="{!c.Type}"/>
             <apex:column value="{!c.Priority}"/>
             <apex:column value="{!c.Day_Created__c}"/>





Apex Code

public class CaseController 

public string getcasetype{get;set;}
public list<case> caselst{get;set;}

public CaseController()
     caselst =  Database.query(
               'SELECT CaseNumber,Contact.Name,Days_Open__c,Subject,Status,Type, Priority, Day_Created__c FROM Case ' +
               'WHERE status=:getcasetype ');   

public void onLoad()


public list<selectoption>getcasestatus()
    list<selectoption>selectopt=new list<selectoption>();
    selectopt.add(new selectoption('Open','Open'));
    selectopt.add(new selectoption('Closed','Closed'));
    return selectopt;

public void displaycaselist()
    caselst=new list<case>();
    caselst=[SELECT CaseNumber,Contact.Name,Days_Open__c,Subject,Status,Type, Priority, Day_Created__c FROM Case WHERE status=:getcasetype AND Owner.Name != 'Dr Sickguy'];


However when the page loads, the list isn't updated until after I change the filter value in the drop-down. I know this is because of the event="onchange" attribute in the element, but I can't find a way to make it load on page load. Adding an event="onLoad" doesn't seem to work, and action methods in the page element don't seem to work when I call displayCaseList();

Any ideas? Many thanks.

  • Have you put a System.debug() at your displaycaselist method and tried page action={!displaycaselist} ?.
    – highfive
    Sep 11, 2015 at 9:27

1 Answer 1


You can set a default value for getcasetype in the controller for exa: Open. Then first time the page load your list is populated.

Second Approach is remove where filte in controller and your list will be populated.Hope it will solve your problem.


You must log in to answer this question.