You need to sign in to do that
Don't have an account?
Problem Binding to Fields in a Child Object
I'm having trouble finding the right binding expression for a VF page. Here's a snippet:
<apex:pageBlock title="Example pageBlockTable">
<apex:pageBlockTable value="{!accounts}" var="item">
THESE WORK:
<apex:column value="{!item.name}"/>
<apex:column value="{!item.owner.name}"/>
But NONE OF THESE REFERENCES TO CHILD FIELDS WORK
<apex:column value="{!item.contracts.lastname}"
<apex:column value="{!item.contract.lastname}"
<apex:column value="{!item.lastname}"
<apex:column value="{!item.contracts[lastname]}"/>
</apex:pageBlockTable>
Here's my controller:
public class CtrlrTestDataTables {
List<Account> accounts;
public List<Account> getAccounts() {
if(accounts == null) accounts =
[select name, owner.name,
(select contact.firstname, contact.lastname from contacts)
from account];
return accounts;
}
}
You have to use an apex:repeat tag. For example, this should work:
Make sure that you're querying all of the fields you reference in the object or you will get an error:
All Answers
You have to use an apex:repeat tag. For example, this should work:
Make sure that you're querying all of the fields you reference in the object or you will get an error:
YES!!!!!!!!!!! Thanks very much for this.
I think it would be very useful for the docset to provide an example like yours in each of the table tag man pages (<apex:pageTableBlock>, <apex:dataTable> etc.) and not just in the page for <apex:repeat>.
I just realized that my wording was misleading in the prior response. You need to use any repeatable tag to list the child items. You may do so in any combination that Visualforce allows. For example, you could do this:
You could use apex:repeat > apex:pageBlock > apex:pageBlockTable, or apex:pageBlock > apex:pageBlockTable > apex:column > apex:repeat, or most any combination of apex:repeat, apex:pageBlockTable, apex:dataTable, and/or apex:dataList, depending on the precise UI you plan on presenting.