1

In a controller I'm populating a list of objects:

public with sharing class SubmittalDashboard {

    public list<Show__c> missingShow {get; set;}

    public void SubmittalDashboard() {

        for (Show__c s : [select Show_Display_Name__c from Show__c]) {
            missingShow.add(s);
        }
    }
}

On a VisualForce page, I'd like to display the contents of the list missingShow in a pageBlockTable:

<apex:page controller="SubmittalDashboard">
<apex:pageBlock title="Missing Submittals">
      <apex:pageBlockTable value="{!missingShow}" var="s">
         <apex:column value="{!s.Show_Display_Name__c}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:page>

When I load everything in and go to the VF page, the table shows up blank -- the title is there but there is no data. When I execute the controller anonymous with debug logging from inside Eclipse, I see that the right data is being added to the missingShow list. So the controller has the right data, but for some reason its not getting to the VF page.

This is the first time I'm using pageBlockTable with a custom controller, so I'm hoping someone out there sees something totally obvious that I'm missing here.

2

Your code has SubmittalDashboard as a method rather than a constructor so missingShow remains null. Before adding to a list you have to create a new instance of it so once you fixed constructor your would get a null pointer exception when you invoked add.

This would be a simpler version of your code:

public with sharing class SubmittalDashboard {

    public list<Show__c> missingShow {get; set;}

    public SubmittalDashboard() {
        missingShow = [select Show_Display_Name__c from Show__c];
    }
}

The Visualforce looks OK.

1
  • Yup, that did it! Of course, no return type for a constructor! Silly error, which I knew it was when I was posting it.
    – eyedar
    Apr 10 '14 at 21:03
0

Without knowing more of your application, another solution is to do a lazy fetch of missingShow only when the VF page needs it such as in this code snippet:

public List<Show__c> missingShow {
  get{
       if (this.missingShow == null) {
          this.missingShow = [select show_display_name__c from Show__c];
       }
       return this.missingShow;
     }
  private set;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.