[SalesForce] How to create tables Dynamically in a VisualForce

Hi My situation is this:

I have a list of different objects and every object has different fields, How can I create N Different Tables in a page ??

Example.
I have this list in an class controller

ObjectName----FieldName <br>
Account---------Name<br>
Account---------LastName<br>
Account---------address<br>
Case------------Name<br>
Case------------Status<br>

So, with this info I have to display two different tables in a page like this:

Account table<br>
Name----LastName----Address

Case Table<br>
Name----Status

In my project I may have even 10 different objects so, I would need 10 different tables created by themself in the , with different number of columns.

I have no Idea how to do this.. someone can help me and save my life???

Best Answer

One option would be to use Dynamic Visualforce Components to build up various apex:pageBlockTable in Apex. With this you can programmatically build up the required apex:column's and bindings.

Your Visualforce page will be something like:

<apex:page controller="DynamicController">
    <apex:dynamicComponent componentValue="{!dynamicPanel}"/>
</apex:page>

With a backing Controller class:

public with sharing Class DynamicController {
    public Component.Apex.OutputPanel getDynamicPanel() {
        Component.Apex.OutputPanel outPanel = new Component.Apex.OutputPanel();

        // Here you will build up the required dynamic components and add them to panel.

        return outPanel;
    }
}