function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JJamesJJames 

Having issues with Apex:Repeat on lists

Not sure why this isn't working, but is it not enough to have get;set; on a list of objects as a getter to use them in a repeat function with a visualforce page?
public List<Custom_Quote_Item__c> quoteItemList {get;set;}

then in the visualforce page:
<apex:repeat value="{!quoteItemList}" var="qi">

I know the list has about 10 items in it but nothing is executing inside the repeat.

I also tried creating a getter function:
public List<Custom_Quote_Item__c> getQuoteItems() {
        return quoteItemList;
    }
but that isn't working either.  I am confused why this isn't working because i am using repeat on a number of lists in my class which all seem to work find but this one isn't.  If anyone has any input I would greatly appreciate it!

Thanks
Mike.KatulkaMike.Katulka

If you use 
  public List<Custom_Quote_Item__c> quoteItemList {get;set;}
then you have to populate quoteItemList in the constructor of the controller.  Are you doing that?


Normally it's a best practice to use full getter pattern without a constructor like

public List<Custom_Quote_Item__c> quoteItemList {
  get{
       if(quoteItemList == null){
           // populate the first time
           quoteItemList = [select id, name from Custom_Quote_Item__c];
       }
       return quoteItemList;
  }
  set;
}

Also on the VF page you can put this in there as a debug to see the size of the list. I've never seen a repeat fail before.

size: {!quoteItemList.size}

JJamesJJames
Thanks for the info, while going through and implementing the getter suggestion you had i saw that the list was decalred again inside of the class making it a local list of the same name as the public list, and thus having an empty list when pulling from the visual force page.  once I took that out it worked as intended.  thanks for the input, simple mistake.