+ Start a Discussion
adrisseladrissel 

Reference index of list

I need to be able to reference the index of a certain value in Visualforce, not the label.  Here is an example:
<apex:pageBlockTable value="{!allData}" var="d" id="theTable">
	<apex:column >
		<apex:facet name="header">Contact Name</apex:facet>
		<apex:outputText value="{!d.Name}"/>
	</apex:column>
<apex:pageBlockTable

In the example above there is usually a label of the object for "Name" that would get pulled in.  However, I had to build a custom list in my controller which doesn't have labels for each index value.  I need something like:
<apex:pageBlockTable value="{!allData}" var="d" id="theTable">
	<apex:column >
		<apex:facet name="header">Contact Name</apex:facet>
		<apex:outputText value="{!d.[index#]}"/>
	</apex:column>
<apex:pageBlockTable

Nothing I try is working.  How can I just call the index place of the value in the list instead of calling it by a label?

Thanks!

 
akramakram
Hi

Are you looking for something like this?
<apex:page controller="listIndexController">
    <apex:pageBlock >
    <apex:pageBlockTable value="{!Lst}" var="l" id="theTable">
    <apex:column >
        <apex:facet name="header">Name</apex:facet>
        <apex:outputText value="{!l[1]}"/>
    </apex:column>
    </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
public with sharing class listIndexController {
    public List<List<String>> getLst()
    {
        List<List<String>> l = new List<List<String>>();
        List<String> lst = new List<String>();
        lst.add('First Value');
        lst.add('Second Value');
        lst.add('Third Value');
        l.add(lst);
        return l;
    }
}
--Akram
 
adrisseladrissel
It is not letting me return a value:
 
Constructor must not return a value

Why?
adrisseladrissel
Here is another error on the VF page:
Incorrect parameter type for subscript. Expected Text, received Number
Does it matter that the output of my data is Set<List<String>> ?
 
adrisseladrissel
Here's the full code of the controller and the VF page.  Please help.

Controller
public with sharing class SupportHistoryController {
    
    public List<Case> listCases {get;set;}
    public List<Contact> conNames {get;set;}
    public List<List<String>> allData {get;set;}
    private List<String> data {get;set;}
    private static Id conId {get;set;}
    private static Id accId {get;set;}
    private static List<User> custUser {get;set;}
    private static List<Contact> con {get;set;}
    private static Boolean superUser {get;set;}
    private static List<Account> parAcc {get;set;}
    private static Id parId {get;set;}
    private static List<Account> childAccList {get;set;}
    private static List<Case> listOpenCases {get;set;}
    private static List<Case> listClosedCases {get;set;}
    private static List<Id> conOpenIds {get;set;}
    private static List<Id> conClosedIds {get;set;}
    private static List<Id> conIds {get;set;}
    private static List<String> strings {get;set;}
    
    // GET ID OF USER LOGGED IN
    
    private static Id userId = Userinfo.getUserId(); 

    public SupportHistoryController(){    }
    
    public List<List<String>> getAllData() {
    
        // GET CONTACTID ASSOCIATED WITH USER LOGGED IN
            
        custUser = [SELECT ContactId FROM User WHERE Id =: userId LIMIT 1]; 
        
        conId = custUser[0].ContactId;  
            
            system.debug('-------------------------------------------------------------> here is the value: '+conId );
         
            
        // GET VALUE OF PORTAL SUPER USER FIELD AND CORRESPONDING ACCOUNTID FOR CONTACT
        
        con = [SELECT Portal_Super_User__c,AccountId FROM Contact WHERE Id =: conId LIMIT 1];
        
        superUser = con[0].Portal_Super_User__c;
        
        accId = con[0].AccountId;    
            
        
        // GET CASES ASSOCIATED WITH THAT CONTACT BASED ON WHETHER THEY ARE CONSIDERED A PORTAL SUPER USER
            
        listCases = new List<Case>();   
        
        if(superUser){   
            
            listOpenCases = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId FROM Case WHERE AccountId =: accId and Status != 'Closed' ORDER BY CreatedDate DESC LIMIT 50];
            
            listClosedCases = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId FROM Case WHERE AccountId =: accId and Status = 'Closed' ORDER BY CreatedDate DESC LIMIT 50];
                        
            listCases.addAll(listOpenCases);
            
            listCases.addAll(listClosedCases);
            
        
            // PUT ALL CONTACTIDS INTO A SINGLE ARRAY
            
            conOpenIds = new List<Id>();
            
            for(Integer a = 0; a < listOpenCases.size(); a++){
            
                conOpenIds.add(listOpenCases[a].ContactId); 
            }
            
            conClosedIds = new List<Id>();
            
            for(Integer b = 0; b < listClosedCases.size(); b++){
            
                conClosedIds.add(listClosedCases[b].ContactId); 
            }
                        
            conIds = new List<Id>();     
                   
            conIds.addAll(conOpenIds);
            
            conIds.addAll(conClosedIds);
            
        
            // GET ALL CONTACT NAMES FOR CONTACTIDS
            
            conNames = new List<Contact>();
            
            conNames = [SELECT Name FROM Contact WHERE Id IN : conIds];
            
            allData = new List<List<String>>();
            
            for(Integer c = 0; c < listOpenCases.size(); c++){
            
                Integer d = 0;
            
                String stat = listOpenCases[c].Status;
                String sub = listOpenCases[c].Subject;
                String des = listOpenCases[c].Description;
                String caseNum = listOpenCases[c].CaseNumber;
                String pri = listOpenCases[c].Priority;
                
                while(conNames[d].Id != listOpenCases[c].ContactId){
            
                    d++;
                }
                
                String conName = conNames[d].Name;
                
                data = new List<String>();
                
                data.add(stat);
                data.add(sub);
                data.add(des);
                data.add(caseNum);
                data.add(pri);
                data.add(conName);
                                
                allData.add(data);
            }             
        }
        
        else{      
            
            listOpenCases = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId FROM Case WHERE ContactId =: conId and Status != 'Closed' ORDER BY CreatedDate DESC LIMIT 50];
            
            listClosedCases = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId FROM Case WHERE ContactId =: conId and Status = 'Closed' ORDER BY CreatedDate DESC LIMIT 50];
                        
            listCases.addAll(listOpenCases);
            
            listCases.addAll(listClosedCases);
           
            
        
            // PUT ALL CONTACTIDS INTO A SINGLE ARRAY
            
            conOpenIds = new List<Id>();
            
            for(Integer a = 0; a < listOpenCases.size(); a++){
            
                conOpenIds.add(listOpenCases[a].ContactId); 
            }
            
            conClosedIds = new List<Id>();
            
            for(Integer b = 0; b < listClosedCases.size(); b++){
            
                conClosedIds.add(listClosedCases[b].ContactId); 
            }
                        
            conIds = new List<Id>();     
                   
            conIds.addAll(conOpenIds);
            
            conIds.addAll(conClosedIds);
            
        
            // GET ALL CONTACT NAMES FOR CONTACTIDS
            
            conNames = new List<Contact>();
            
            conNames = [SELECT Name FROM Contact WHERE Id IN : conIds];
            
            allData = new List<List<String>>();
            
            for(Integer c = 0; c < listOpenCases.size(); c++){
            
                Integer d = 0;
            
                String stat = listOpenCases[c].Status;
                String sub = listOpenCases[c].Subject;
                String des = listOpenCases[c].Description;
                String caseNum = listOpenCases[c].CaseNumber;
                String pri = listOpenCases[c].Priority;
                
                while(conNames[d].Id != listOpenCases[c].ContactId){
            
                    d++;
                }
                
                String conName = conNames[d].Name;
                
                data = new List<String>();
                
                data.add(stat);
                data.add(sub);
                data.add(des);
                data.add(caseNum);
                data.add(pri);
                data.add(conName);
                                
                allData.add(data);
            }
        }
                
        return allData;
    }
    
    
    // CODE NEEDED FOR SUPREME USER (ABLE TO SEE ALL CASES UNDER ALL ACCOUNTS IN MASTER HEIRARCHY)
    
    /*   
    parAcc = [SELECT ParentId FROM Account WHERE Id =: accId LIMIT 1];
    
    if(!parAcc.isEmpty()){
        
        parId = parAcc[0].ParentId;
        
        childAccList = [SELECT Id FROM Account WHERE ParentId =: parId];
        
    }
     
        
    if(parId != null){
    
        for(Account childAcc : childAccList){
        
            accId = childAcc.Id;
    
            List<Case> listOpenCase = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId FROM Case WHERE AccountId =: accId and Status != 'Closed' ORDER BY CreatedDate DESC LIMIT 100];
            
            List<Case> listClosedCase = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId FROM Case WHERE AccountId =: accId and Status = 'Closed' ORDER BY CreatedDate DESC LIMIT 100];
                        
            listCases.addAll(listOpenCase);
            
            listCases.addAll(listClosedCase);
        } 
    }
    
    else{
    
    
    }
    */
}

VF Page
<apex:page controller="SupportHistoryController" showHeader="false">
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Sciquest SelectSite Support</title>
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js" />
    <apex:stylesheet value="{!URLFOR($Resource.SQI_icon_set, '/webfonts/ss-symbolicons-block.css')}"/>
    <apex:includeScript value="{!URLFOR($Resource.SQI_icon_set, '/webfonts/ss-symbolicons-block.js')}"/>
    <apex:includeScript value="{!URLFOR($Resource.SFDC_Portals, 'responsiveCategories.js')}"/>
    <apex:stylesheet value="{!URLFOR($Resource.SFDC_Portals, 'main_stylesheet.css')}"/>

    <script type="text/javascript">
    j$ = jQuery.noConflict();
    j$(document).ready(function(){
            j$("section table tr td a:contains('Next')").wrap("<i class='ss-icon'></i>");
            j$("section table tr td a:contains('Previous')").wrap("<i class='ss-icon'></i>");
            });
    //script for resizing the tables
    j$(document).ready(function(){
    j$('td.dataCell:last-of-type').each(function(){
        j$(this).css('max-width','800px');
        var contentOfCell = j$(this).text();    
        var  shortenedText = (contentOfCell.length > 600) ? contentOfCell.substring(0, contentOfCell.indexOf(" ", 390))+'...' : contentOfCell;
        j$(this).text(shortenedText);
    });
});
    </script>

</head>
<style>
     #datePicker{display:none;}
</style>

<body>
    <div class="body-wrapper">

    <apex:form >
        <c:SS_header isSearch="true"></c:SS_header>
        <section class="banner clearfix">
            <div id="SearchWrapper" class="wrapper">
                <div class="grid">
                 <fieldset class="col-2-3">
                   <!-- <div id="SearchWrapperLabel">{!$Label.Search_KnowledgeBase}</div>-->
                    <div class="searchWidget" role="search">
                        <!--<apex:inputText value="{!searchstring}" styleclass="SearchWrapperInput" maxlength="100" size="102" /> &nbsp;
                        <apex:commandButton value="{!$Label.Search}" id="submitButton" action="{!searchArticle}" />     -->               
                     </div>
                 </fieldset> 
                </div>
            </div>
            </section>
                <div class="main-container clearfix">
                        <div class="main wrapper grid grid-pad">
                        <section class="" role="main"> 
                            <article class="clearfix">  
                        <apex:pageBlock title="Support History">
                                 <apex:pageBlockTable value="{!AllData}" var="d" id="theTable">
                                   <apex:column >
                                        <apex:facet name="header">Contact Name</apex:facet>
                                        <apex:outputText value="{!d[1]}"/>
                                    </apex:column>
                                    <apex:column >
                                        <apex:facet name="header">Case Number</apex:facet>
                                        <apex:outputText value="{!d[2]}"/>
                                    </apex:column>
                                    <apex:column >
                                        <apex:facet name="header">Subject</apex:facet>
                                        <apex:outputLink target="_blank" value="/apex/SS_Support_View?Id={!d[3]}&isdtp=vw">{!d[3]}</apex:outputLink>
                                    </apex:column>
                                     <apex:column >
                                        <apex:facet name="header">Status</apex:facet>
                                        <apex:outputText value="{!d[4]}"/>
                                    </apex:column>
                                    <apex:column >
                                        <apex:facet name="header">Priority</apex:facet>
                                        <apex:outputText value="{!d[5]}"/>
                                    </apex:column>
                                    <apex:column >
                                        <apex:facet name="header">Description</apex:facet>
                                        <apex:outputText value="{!d[6]}"/>
                                    </apex:column>  
                            </apex:pageBlockTable>
                        </apex:pageBlock>
                            </article>
                            <article class=" col-2-3 clearfix buttons">
                            <c:SS_buttons ></c:SS_buttons>    
                            </article>
                            </section>
                    </div>
                </div>
    </apex:form>
        <div class="push">           
        </div>
    </div>



<c:SS_footer ></c:SS_footer>

</body>
</apex:page>

 
akramakram
User this controller:
public with sharing class SupportHistoryController {
    
    public List<Case> listCases {get;set;}
    public List<Contact> conNames {get;set;}
    private List<List<String>> allData;
    private List<String> data {get;set;}
    private static Id conId {get;set;}
    private static Id accId {get;set;}
    private static List<User> custUser {get;set;}
    private static List<Contact> con {get;set;}
    private static Boolean superUser {get;set;}
    private static List<Account> parAcc {get;set;}
    private static Id parId {get;set;}
    private static List<Account> childAccList {get;set;}
    private static List<Case> listOpenCases {get;set;}
    private static List<Case> listClosedCases {get;set;}
    private static List<Id> conOpenIds {get;set;}
    private static List<Id> conClosedIds {get;set;}
    private static List<Id> conIds {get;set;}
    private static List<String> strings {get;set;}
    
    // GET ID OF USER LOGGED IN
    
    private static Id userId = Userinfo.getUserId(); 

    public SupportHistoryController(){    }
    
    public List<List<String>> getAllData() {
    
        // GET CONTACTID ASSOCIATED WITH USER LOGGED IN
            
        custUser = [SELECT ContactId FROM User WHERE Id =: userId LIMIT 1]; 
        
        conId = custUser[0].ContactId;  
            
            system.debug('-------------------------------------------------------------> here is the value: '+conId );
         
            
        // GET VALUE OF PORTAL SUPER USER FIELD AND CORRESPONDING ACCOUNTID FOR CONTACT
        
        con = [SELECT Portal_Super_User__c,AccountId FROM Contact WHERE Id =: conId LIMIT 1];
        
        superUser = con[0].Portal_Super_User__c;
        
        accId = con[0].AccountId;    
            
        
        // GET CASES ASSOCIATED WITH THAT CONTACT BASED ON WHETHER THEY ARE CONSIDERED A PORTAL SUPER USER
            
        listCases = new List<Case>();   
        
        if(superUser){   
            
            listOpenCases = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId, Contact.Name FROM Case WHERE AccountId =: accId and Status != 'Closed' ORDER BY CreatedDate DESC LIMIT 50];
            
            listClosedCases = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId FROM Case WHERE AccountId =: accId and Status = 'Closed' ORDER BY CreatedDate DESC LIMIT 50];
                        
            listCases.addAll(listOpenCases);
            
            listCases.addAll(listClosedCases);
            
        
            // PUT ALL CONTACTIDS INTO A SINGLE ARRAY
            
            conOpenIds = new List<Id>();
            
            for(Integer a = 0; a < listOpenCases.size(); a++){
            
                conOpenIds.add(listOpenCases[a].ContactId); 
            }
            
            conClosedIds = new List<Id>();
            
            for(Integer b = 0; b < listClosedCases.size(); b++){
            
                conClosedIds.add(listClosedCases[b].ContactId); 
            }
                        
            conIds = new List<Id>();     
                   
            conIds.addAll(conOpenIds);
            
            conIds.addAll(conClosedIds);
            
        
            // GET ALL CONTACT NAMES FOR CONTACTIDS
            
            conNames = new List<Contact>();
            
            conNames = [SELECT Name FROM Contact WHERE Id IN : conIds];
            
            allData = new List<List<String>>();
            
            for(Integer c = 0; c < listOpenCases.size(); c++){
            
                String stat = listOpenCases[c].Status;
                String sub = listOpenCases[c].Subject;
                String des = listOpenCases[c].Description;
                String caseNum = listOpenCases[c].CaseNumber;
                String pri = listOpenCases[c].Priority;
                
                /*while(conNames[d].Id != listOpenCases[c].ContactId){
            
                    d++;
                }*/
                
                String conName = listOpenCases[c].Contact.Name;//conNames[d].Name;
                
                data = new List<String>();

                conName = (conName == null ? '': conName);
                caseNum = (caseNum == null ? '': caseNum);
                sub = (sub == null ? '': sub);
                stat = (stat == null ? '': stat);
                pri = (pri == null ? '': pri);
                des = (des == null ? '': des);
                data.add(stat);
                data.add(sub);
                data.add(des);
                data.add(caseNum);
                data.add(pri);
                data.add(conName);
                allData.add(data);
            }             
        }
        
        else{      
            
            listOpenCases = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId, Contact.Name FROM Case WHERE ContactId =: conId and Status != 'Closed' ORDER BY CreatedDate DESC LIMIT 50];
            
            listClosedCases = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId FROM Case WHERE ContactId =: conId and Status = 'Closed' ORDER BY CreatedDate DESC LIMIT 50];
                        
            listCases.addAll(listOpenCases);
            
            listCases.addAll(listClosedCases);
           
            
        
            // PUT ALL CONTACTIDS INTO A SINGLE ARRAY
            
            conOpenIds = new List<Id>();
            
            for(Integer a = 0; a < listOpenCases.size(); a++){
            
                conOpenIds.add(listOpenCases[a].ContactId); 
            }
            
            conClosedIds = new List<Id>();
            
            for(Integer b = 0; b < listClosedCases.size(); b++){
            
                conClosedIds.add(listClosedCases[b].ContactId); 
            }
                        
            conIds = new List<Id>();     
                   
            conIds.addAll(conOpenIds);
            
            conIds.addAll(conClosedIds);
            
        
            // GET ALL CONTACT NAMES FOR CONTACTIDS
            
            conNames = new List<Contact>();
            
            conNames = [SELECT Name FROM Contact WHERE Id IN : conIds];
            
            allData = new List<List<String>>();
            
            for(Integer c = 0; c < listOpenCases.size(); c++){
            
            
                String stat = listOpenCases[c].Status;
                String sub = listOpenCases[c].Subject;
                String des = listOpenCases[c].Description;
                String caseNum = listOpenCases[c].CaseNumber;
                String pri = listOpenCases[c].Priority;
                
                /*while(conNames[d].Id != listOpenCases[c].ContactId){
            
                    d++;
                }*/
                
                String conName = listOpenCases[c].Contact.Name;//conNames[d].Name;
                
                data = new List<String>();

                conName = (conName == null ? '': conName);
                caseNum = (caseNum == null ? '': caseNum);
                sub = (sub == null ? '': sub);
                stat = (stat == null ? '': stat);
                pri = (pri == null ? '': pri);
                des = (des == null ? '': des);
                data.add(stat);
                data.add(sub);
                data.add(des);
                data.add(caseNum);
                data.add(pri);
                data.add(conName);
                allData.add(data);
            }
        }
                
        return allData;
    }
    
    
    // CODE NEEDED FOR SUPREME USER (ABLE TO SEE ALL CASES UNDER ALL ACCOUNTS IN MASTER HEIRARCHY)
    
    /*   
    parAcc = [SELECT ParentId FROM Account WHERE Id =: accId LIMIT 1];
    
    if(!parAcc.isEmpty()){
        
        parId = parAcc[0].ParentId;
        
        childAccList = [SELECT Id FROM Account WHERE ParentId =: parId];
        
    }
     
        
    if(parId != null){
    
        for(Account childAcc : childAccList){
        
            accId = childAcc.Id;
    
            List<Case> listOpenCase = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId FROM Case WHERE AccountId =: accId and Status != 'Closed' ORDER BY CreatedDate DESC LIMIT 100];
            
            List<Case> listClosedCase = [SELECT Status,Id,Subject,Priority,Description,CaseNumber,ContactId FROM Case WHERE AccountId =: accId and Status = 'Closed' ORDER BY CreatedDate DESC LIMIT 100];
                        
            listCases.addAll(listOpenCase);
            
            listCases.addAll(listClosedCase);
        } 
    }
    
    else{
    
    
    }
    */
}