[SalesForce] How to display a list of leads in a Visualforce pageBlockTable

Following the Visualforce example here, I can display the list of account names in a pageblocktable but changing the controller to Lead does not display the list of lead names. Why not? It works great with the Contact controller as well, but not the Lead controller.

According to this page, the Lead controller is also a type of standard list controller and it seems this simple thing should work. What am I missing?

Here's the complete source of the page:

<apex:page standardController="Lead" recordSetVar="leads" tabstyle="lead" sidebar="false">
   <apex:pageBlock >
    <apex:pageBlockTable value="{!leads}" var="ld">
      <apex:column value="{!ld.name}"/>
    </apex:pageBlockTable>
  </apex:pageBlock>
</apex:page>

Best Answer

I took the Account example from your first link, and changed each Account reference to lead.

EDIT: From the doc page you link above, "This page does not specify a filter in the request, so the page is displayed with the last used filter." In my testing, my last used Lead filter happened to be "All Open Leads". If your last used filter shows no leads (e.g., "My Leads" if you don't own any leads), then the standard controller won't load any records by default. I've updated the code to show a List View dropdown for the standard controller using code from this doc page on using list views with standard controllers.

<apex:page standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false">
  <apex:pageBlock >
    <apex:form >
      <apex:panelGrid columns="2">
        <apex:outputLabel value="View:"/>
        <apex:selectList value="{!filterId}" size="1">
          <apex:actionSupport event="onchange" rerender="list"/>
          <apex:selectOptions value="{!listviewoptions}"/>
        </apex:selectList>
      </apex:panelGrid>
      <apex:pageBlockTable value="{!accounts}" var="a" id="list">
        <apex:column value="{!a.name}"/>
      </apex:pageBlockTable>
    </apex:form>
  </apex:pageBlock>
</apex:page>

Note the use of apex:actionSupport to update the list in real time using the rerender param, and the addition of a matching id on the pageBlockTable for the rerender to reference.