+ Start a Discussion
NickOlendorfNickOlendorf 

Columns not displaying using Apex:repeat

Good evening,

 

I am a novice Apex developer, and I have been having some issues getting the below code to work.  At this point, I am sure I am missing something, but I have tried so many things, I am not sure what it is!  I have created three custom objects:

 

Organizational_Goal__c, Departmental_Goal__c, and Individual_Goal__c

 

These objects are set up with a Master-Detail relationship, and what I want to do is to display the goals in a table, beginning on the left with the Org Goal, then in the middle column, I would like the Dept Goal, then lastly in the right column the Ind. Goal.  Initially, I had the Org and Dept Goals duplicated, as each one was listed for each Ind. Goal.  It ends up being too much data in the table, similar to what I found with the report.  I just want to bring back the Name and ID of each Individual Goal, and it's related Dept and Org Goals, without having them repeated in the table.  So it should look something like this:

 

Organizational Goal

Departmental Goal

Individual Goal

Org Goal #1

Dept Goal #1.1

 

Individual Goal #1.1.1

Individual Goal #1.1.2

Individual Goal #1.1.3

Dept Goal #1.2

Individual Goal #1.2.1

Individual Goal #1.2.2

Individual Goal #1.2.3

Dept Goal #1.3

Individual Goal #1.3.1

Individual Goal #1.3.2

Individual Goal #1.3.3

Org Goal #2

Dept Goal #2.1

 

Individual Goal #2.1.1

Individual Goal #2.1.2

Individual Goal #2.1.3

Dept Goal #2.2

Individual Goal #2.2.1

Individual Goal #2.2.2

Individual Goal #2.2.3

Dept Goal #2.3

Individual Goal #2.3.1

Individual Goal #2.3.2

Individual Goal #2.3.3

 

 

 The alignment on the table was altered when I tried to submit, but the goals should all be lined up under their respective headings.

 

Right now I can only seem to either get the Org and Dept to duplicate - or - I only see Org Goals.

 

Here is my controller code:

 

public class GoalList {
public ApexPages.StandardSetController setQuery1 {
        get {
            if(setQuery1 == null) {
                setQuery1 = new ApexPages.StandardSetController(Database.getQueryLocator(
                
                    [SELECT ID, Name, (SELECT ID, Name FROM Departmental_Goals__r) FROM Organizational_Goal__c 
                    ]));                                                  
            }
            return setQuery1;

        }
        set;
    }
          
    // Initialize setCon and return a list of records 
    public List<Organizational_Goal__c> getGoals() {
        return (List<Organizational_Goal__c>) setQuery1.getRecords();
    }   
}

 

 

Here is my VF page code:

 

<apex:page controller="GoalList">
    <apex:pageBlock >
    <apex:pageBlockTable value="{!Goals}" var="o">
    <apex:column value="{!o.Name}"/>
        <apex:repeat id="ColumnsRpt" value="{!o.Departmental_Goals__r}" var="col">   
               <apex:pageBlockTable value="{!col}" var="ac">
                        <apex:column value="{!ac.Name}"/>
               </apex:pageBlockTable>         
         </apex:repeat>              
    </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

 

Any suggestions for a total newbie?

 

Thanks for your help!

 

Troy

 

 

crop1645crop1645

Have you tried using dataTable rather than pageBlockTable?

 

The VF doc doesn't suggest that pageBlockTable can be inside another pageBlockTable

NickOlendorfNickOlendorf

Hi Eric,

 

I have not tried dataTable, but I could give that a shot.  I haven't used that before.  As for the nested pageBlockTable, I saw in another post where someone had suggested that and apparently it worked.  Whether they had to massage it to get it to work properly I do not know, but you certainly could be right about that.  I will see what I can do with pageBlockTable.  Thanks for the suggestion!

 

Regards,

 

Troy