I am trying to create a VisualForce page that display 3 objects. I want it in a way where I want to see a parent and all child records underneath. I tried using a nested repeater however It displays the Parent and all children records even if it is not related to that parent.
I researched the best way to handle what I am trying to accomplish and I think using a repeater with lists is the best approach but again it is displaying the parent correctly, but the child records are displaying under the parent even if it is not related to the parent.
Controller:
public class G_SPRFormExtension {
Private SBQQ__Quote__c soQuote {get;set;}
public List<Host__c> lstHost {get;set;}
public List<Asset> lstHost_Assets {get;set;}
Private Set<Id> idHostAsset = new Set<Id>();
//public List<Contact> cont{get;set;}
Public String getAccountID() {
return soQuote.SBQQ__Account__c;
}
Public G_SPRFormExtension(ApexPages.StandardController stdController)
{
system.debug(logginglevel.debug, 'DEBUG: START CONSTRUCTOR');
// Get Case ID number
This.soQuote = (SBQQ__Quote__c)stdController.getRecord();
//Get the Case Values for this record
soQuote = [Select Id, Name, SBQQ__Account__c
From SBQQ__Quote__c
Where Id = :This.soQuote.Id];
system.debug(logginglevel.debug, 'DEBUG: soQuote' + soQuote );
GetHosts();
}
Public Void GetHosts()
{
lstHost = [Select Id, Name
From Host__c
Where Location__c = :soQuote.SBQQ__Account__c];
system.debug(logginglevel.debug, 'DEBUG: lstHost ' + lstHost);
for (Host__c soHost : lstHost){
idHostAsset.add(soHost.Id);
}
GetHostAssets();
}
Public Void GetHostAssets()
{
system.debug(logginglevel.debug, 'DEBUG: idHostAsset' + idHostAsset );
lstHost_Assets = [Select Id, Name
From Asset
Where Host__c = :idHostAsset];
}
}
Page:
<apex:page standardController="SBQQ__Quote__c" extensions="G_SPRFormExtension" >
<apex:pageBlock>
<apex:pageblocksection columns="2">
<apex:outputField value="{!SBQQ__Quote__c.name}"/>
</apex:pageBlockSection>
<apex:repeat var="a" value="{!lstHost}">
<apex:pageBlock title="Host">
<apex:pageblocksection columns="2">
<apex:outputPanel id="Host">
<apex:outputText value="{!a.Name}"/>
<apex:repeat var="asset" value="{!lstHost_Assets}">
<apex:outputText value="{!asset.Name}"/>
</apex:repeat>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:repeat>
</apex:pageBlock>
</apex:page>