Based on my earlier question i had built up a wrapper class to display in the format below.

  Area            Allocated   Currently available
 - New York       20              15
    Vendor1       10              10
    Vendor2       10              5

 - Philadelphia   10              8
    Vendor1       5               5
    Vendor2       5               3

public class HDDevicesbyArea
        public string HD_Area{get;set;}
        public double HD_Current {get;set;}
        public string HD_Allocated {get; set;}
        List<HDDevicesbyVendor> ListHDDevicesbyVendor {get; set;}
        public HDDevicesbyArea ( string HD_Area_v, string allocated_v, List<HDDevicesbyVendor> ListHDDevicesbyVendor_v )
         // constructor code

How should i have my VF page to set show the inner list also show in the same columns? I have a Lsit of class HDDevicesArea which i would repeat in VF page. I also have List ListHDDevicesbyVendor within the class HDDevicesbyArea

I need to show ListHDDevicesbyVendor using the same columns as HDDevicesbyArea

<apex:pageBlock id="theResultBlock" >
    <apex:pageBlockSection id="ResultSection" columns="1" >
     <table width="100%" cellpadding ="1" cellspacing = "1">
            <th>Area / Vendor</th>

              <apex:repeat value="{!HDDevicesbyArea}" var="HD" id="theRepeat">
              <td><apex:outputText value= "{!HD.HD_Vendor"} /></td>
              <td><apex:outputText value= "{!HD.HD_Current"}</td>
              <td><apex:outputText value= "{!HD.HD_Allocated"}</td>

Thanks in Advance

  • Hi Prady, it'd be easier to give an accurate solution if you show what your VF looks like already, otherwise a suggested solution may not fit with what you have.
    – Matt Lacey
    Oct 22 '12 at 5:55
  • @LaceySnr i have updated the VF page which i have till now. I could use <apex:DataTable> instead of just the HTML table but was not sure on how i can achived showing the vendors also in the same columns
    – Prady
    Oct 22 '12 at 6:33

I'd avoid using datatable as per your comments, as its quite difficult to do anything other than iterate a common set of data and output a column per property. I think this is simply a matter of iterating the inner list and generating its own HTML table rows. E.g.

<apex:repeat value="{!HDDevicesbyArea}" var="HD" id="theRepeat">
     <td><apex:outputText value= "{!HD.HD_Area"} /></td>
     <td><apex:outputText value= "{!HD.HD_Current"}</td>
     <td><apex:outputText value= "{!HD.HD_Allocated"}</td>

  <apex:repeat value="{!HD.ListHDDevicesbyVendor}" var="dev">
     <td><apex:outputText value= "{!dev.HD_Vendor}" /></td>
     <td><apex:outputText value= "{!dev.HD_Current"}</td>
     <td><apex:outputText value= "{!dev.HD_Allocated"}</td>

That way the first row in the repeat contains the area and current/allocated, and the following rows contain the vendor and the current/allocated.

  • could you please add the controller for this page ? Sep 23 '14 at 5:55
  • I don't have a controller - this is based on the OP question, I've simply altered their markup. Sep 23 '14 at 10:34
  • wouldn't this give the error: "Object type not accessible. Please check permissions and make sure the object is not in development mode: SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object."? - edit: oh right, the OP's controller will allow nested <apex:repeat> tags Jan 18 '17 at 3:03

I would imagine two structures, one for traversing and one for looking up to:

Map <string, HDDevicesbyArea> allocationMap


List <string> keyNames

In the List keep adding the list of values as in the hierarchy, eg {NewYork, NYVendor1, NYVendor2, Philadelphia, PHVendor 1, PHVendor2}

In your apex:repeat iterate over this flat list,

However to render fetch details from the map allocationMap[var]

<apex:repeat value="{!keyNames}"  var="keyName">
 <td><apex:outputText value= "{!allocationMap[keyName].HD_Vendor"} /></td>
 <td><apex:outputText value= "{!allocationMap[keyName].HD_Current"}</td>
 <td><apex:outputText value= "{!allocationMap[keyName].HD_Allocated"}</td>

In this way you traverse over a flat list but lookup to the Map for rendering

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.