+ Start a Discussion
momorganmomorgan 

Rendering a table from a list

I think I'm missing something trivial, but I can't see it so I wonder if you can. The expected result of the code below is a table with five rows, but nothing is returned from the Apex code. Can anyone advise?

 

Here's the Apex:

 

 

public class listdemo { public List<selectOption> getFoodstuffOptions() { List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('A Fish', 'A Fish')); options.add(new SelectOption('Some Chips', 'Some Chips')); return options; } public class tempList{ public String foodstuff {get; set;} public Integer quantity {get; set;} public tempList(string inFoodstuff, integer inQuantity){ foodstuff = inFoodstuff; quantity = inQuantity; } } public List<tempList> ListOne {get; set;} public List<tempList> getListOne(){ if(ListOne == null){ ListOne = new List<tempList>(); for (Integer c = 0; c < 5; c++){ ListOne.add(new tempList('Something',1)); } } return ListOne; } }

 

Here's the VF:

 

 

<apex:page Controller="listdemo"> <apex:form > <apex:pageblock mode="edit"> <apex:pageblockTable value="{!ListOne}" var="l"> <apex:column headervalue="Foodstuff"> <apex:actionRegion > <apex:selectlist value="{!l.foodstuff}" multiselect="false" size="1" required="true"> <apex:selectOptions value="{!foodstuffoptions}" /> <apex:actionSupport event="onchange" rerender="quantitycolumn" /> </apex:selectlist> </apex:actionRegion> </apex:column> <apex:column headervalue="Quantity" id="quantitycolumn"> <apex:inputText required="true" value="{!l.quantity}" rendered="{!l.foodstuff == 'Some Chips'}" /> </apex:column> </apex:pageblockTable> </apex:pageBlock> </apex:form> </apex:page>

 

 

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
wesnoltewesnolte

Hey

 

You just need a small tweak. You've got a public property called 'ListOne' and a getter called 'getListOne ()' and I think your page is fetchign the first(empty) property. Simply make the property private and it will work (I just tested).

 

public List<tempList> ListOne {get; set;}

 must change to

 

private List<tempList> ListOne;

 

Cheers,

Wes

All Answers

wesnoltewesnolte

Hey

 

You just need a small tweak. You've got a public property called 'ListOne' and a getter called 'getListOne ()' and I think your page is fetchign the first(empty) property. Simply make the property private and it will work (I just tested).

 

public List<tempList> ListOne {get; set;}

 must change to

 

private List<tempList> ListOne;

 

Cheers,

Wes

This was selected as the best answer
momorganmomorgan
Quite right! Thank you.