You need to sign in to do that
Don't have an account?
Jim Boudreaux
DataTable as Related List
Alright, here's another one.
I am making a visualforce page that displays data from a custom object and its two related lists. I successfully used the <apex:relatedlist> tag by setting the list="MonitoringContacts__r" which is how you specify a Child Relationship Name.
While it worked, the rendered result maintained Salesforce's look and feel which is what i am trying to avoid here.
What I want is a list of data from a related list, but i want to control what the final product looks like. So I settled on a DataTable. This is the code I used to render a DataTable containing Related List info, using the Child Relationship naming convention mentioned earlier (I only have one column here for simplicity)
Most of this is apparently right because I only get an error for the last part, the part where I set the OutputText value="{!Monitoring_Agreement__c.MonitoringContacts__r.password__c}"
The error I get is:
Error: The class 'java.util.ArrayList' does not have the property 'password__c'.
I have gotten this error before, so I must be misunderstanding something.
What i am looking for from you guys and gals is
I am making a visualforce page that displays data from a custom object and its two related lists. I successfully used the <apex:relatedlist> tag by setting the list="MonitoringContacts__r" which is how you specify a Child Relationship Name.
While it worked, the rendered result maintained Salesforce's look and feel which is what i am trying to avoid here.
What I want is a list of data from a related list, but i want to control what the final product looks like. So I settled on a DataTable. This is the code I used to render a DataTable containing Related List info, using the Child Relationship naming convention mentioned earlier (I only have one column here for simplicity)
Code:
<apex:datatable value="{!Monitoring_Agreement__c.MonitoringContacts__r}" var="Contact"> <apex:facet name="caption">table caption</apex:facet> <apex:facet name="header">table header</apex:facet> <apex:facet name="footer">table footer</apex:facet> <apex:column> <apex:facet name="header">Password</apex:facet> <apex:facet name="footer">column footer</apex:facet> <apex:outputText value="{!Monitoring_Agreement__c.MonitoringContacts__r.password__c}"/> </apex:column> </apex:datatable>
The error I get is:
Error: The class 'java.util.ArrayList' does not have the property 'password__c'.
I have gotten this error before, so I must be misunderstanding something.
What i am looking for from you guys and gals is
- How do I display a Related List in a DataTable?
- How do I specify elements of an ArrayList so as to avoid the above error?
I know I just responded to your other thread but yep, pageBlockTable is the way to go.
First, pageBlockTable and dataTable are iterators. Think of it like a java "for each" loop:
for (Contact c : ListofContacts) {
}
You are now free to use c in your loop. Same applies here, you supply a var called Contact that represents one contact in the list (value attribute) you supplied.
Also notice that I collapsed the footer facet and removed the header facet entirely. pageBlockTable will automatically generate your headers for you if you're using the value attribute bound to an sobject field (though you can still supply it if you want using headerValue, and you can still use the facet if you wanted to put an image or a link, for example, as your column header)
You can replace pageBlockTable with dataTable, and then you'll have to add headerValue back into your column. Everything else should still work!
I'm guessing that you're using the standardController, so you'll want to also add an extension. Then for dataTable you'll do value="{!contactList}".
In your extension create a method called public MonitoringContacts__c[] getContactList() that does a query for all of your monitoring contacts using the ORDER BY operator in SOQL.
In that case, how about this:
If I bind a dataTable to a Related List, <apex:datatable value="{!Custom_Object__c.Related_Object__r}" var="variable" />, is there a way to have the entries iterated in the datatable do so in the same order in which they are listed in the related list?
To illustrate, I have a custom object that has a related list of people to call in an emergency. The custom object for these people has a custom field that indicates the order in which they should be called. The related list orders them according to that field. Given that there is no way to order data in the VF markup, wouldn't it make sense that the data that is retrieved is done so in the same manner that the related list is done, so that my datatable returns data in the same order that the related list does on my standard salesforce UI?