+ Start a Discussion
ThomasmThomasm 

VisualForce page with table

i am trying to get a custom object and its related items to show in a table in a visualforce page.  Currently i have the first object showing up but i am not sure how to pull in the related list

 

here is the controller

global with sharing class poistionController {
private Map<string,set<String>> employeeMap=new Map<string,set<String>>();

     public Employees__c pos{get;set;}

     public poistionController() {
        list<Training__C>trainList=[Select name from Training__C where employee__C=:employees__C.Name__c];
         pos = [select ID, Name, Active__C from Employees__c where Active__C= true];

      }

}

 

and here is the page

<apex:page controller="poistionController" showHeader="false">
<apex:relatedList list="Training__C"/>
  
      <apex:pageblock title="test">
      </apex:pageblock>
     
      <apex:dataTable value="{!pos}" var="Employee">
     
     
         <apex:column value="{!pos.name}">
         </apex:column>
        
         <apex:column value="{!pos.id}">
         </apex:column>
         </apex:dataTable>
 

 


</apex:page>

kevin Carotherskevin Carothers
Hi,
I think what you need is a nested apex:repeat - given that you have what looks like two related objects.

Just taking a wild hack at your problem, see if this is sorta/kinda what you're looking for;

Page:
<apex:page controller="TrainingSearchController">
<apex:repeat value="{!employeeList}" var="key">
    <apex:outputText value="{!key.Name}" />
    <ul>
   <apex:repeat value="{!trainingMap[key]}" var="map">
       <Apex:outputText value="{!map.Name}"/> <br/>
   </apex:repeat>
   </ul>
</apex:repeat>
</apex:page>

Controller:

public class TrainingSearchController {   
    public  List<Employee__c> employeList = [Select ID, Name FROM Employee__c];
    public  Map<Id,List<Training__c>> trainingMap = new Map<Id,List<Training__c>>();
    
    
    public TrainingSearchController(){  
          List<Id> theEids = new List<Id>();
          
          for(Employee__c e :employeList) {
              theEids.add(e.Id);
              List<Training__c> l = new List<Training__c>();
              trainingMap.put(e.Id, l);
              }
              
          for(Training__c  t:[Select Id, Name, Employee__r.Id From Training__c WHERE Employee__r.Id IN :theEids] ) {
              trainingMap.get(t.Employee__r.Id).add(t);
              }
        }

   public Map<Id,List<Training__c>> gettrainingMap(){
        return trainingMap;
    }

   public List<Employee__c> getemployeeList(){
        return employeList;
    }
 }

PS- There are much more eloquent ways to build maps of lists - this is just an example.

Plus - this solution might not at all match your problem -- because in the "typical" class/pupil problem, there is a many to many relationship -- multiple pupils can take multiple classes, and vice-versa.   If that is your case, you'll need to build a junction object to link the employees to your classes.