I am trying to iterate map<Integer,List> on the vf page using apex:PageBlockTable. Here List contains multiple accounts. I am getting each value of map in a single row. How do I get each account in single row using map and apex:PageBlockTable.
Visualforce Page:
<apex:page controller="ShowAccountsController">
<apex:form >
<apex:commandButton value="Show Accounts" action="{!displayAccounts}" />
<apex:pageBlock title="Accounts" id="accountPageBlock">
<apex:inputFile value="{!fileBody}" />
<apex:pageBlockTable value="{!mapOfPageNumberAndRecords}" var="indexValue" >
<apex:repeat value="{!mapOfPageNumberAndRecords[indexValue]}" var="ac">
<apex:column>
<apex:facet name="header"> Account Name</apex:facet>
<apex:outputText value="{!ac.Name}"/>
</apex:column>
<apex:column>
<apex:facet name="header"> Account Id</apex:facet>
<apex:outputText value="{!ac.Id}"/>
</apex:column>
</apex:repeat>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page> Controller:
public class ShowAccountsController {
Public Integer Page_Size;
Public Map<Integer,List<Account>> mapOfPageNumberAndRecords {get;set;}
Public List<Account> emptyList {get;set;}
Public Integer currentPageNumber {get;set;}
Public Integer Counter;
Public Integer Page_Number;
public Blob fileBody { get; set; }
public ShowAccountsController(){
currentPageNumber = 1;
Page_Size = 1000;
Counter = 0;
Page_Number =0;
mapOfPageNumberAndRecords = new Map<Integer,List<Account>>();
emptyList = new List<Account>();
mapOfPageNumberAndRecords.put(null, new List<Account>());
//retrieveAccountRecords();
system.debug('mapOfPageNumberAndRecords is '+mapOfPageNumberAndRecords);
}
public void displayAccounts(){
retrieveAccountRecords();
}
public void retrieveAccountRecords(){
List<Account> listOfAccountsPerPage = new List<Account>();
List<Account> listOfAccountRecords = [select id,name,Industry from account];
Integer totalRecordsProcessed = 0;
Integer remainingRecords = 0;
if(listOfAccountRecords.size()<Page_Size){
Page_Number = Page_Number+ 1;
mapOfPageNumberAndRecords.put(Page_Number,listOfAccountRecords);
}
else{
for(Account accountRec : listOfAccountRecords){
totalRecordsProcessed++;
Counter++;
listOfAccountsPerPage.add(accountRec);
if(Counter == Page_Size){
system.debug('Counter is '+Counter);
system.debug('totalRecordsProcessed is '+totalRecordsProcessed);
Page_Number = Page_Number+ 1;
mapOfPageNumberAndRecords.put(Page_Number,listOfAccountsPerPage);
remainingRecords = listOfAccountRecords.size() - totalRecordsProcessed;
if(remainingRecords <= Page_Size && remainingRecords!=0){
Page_Size = listOfAccountRecords.size()-totalRecordsProcessed;
}
system.debug('Page_Size is '+Page_Size);
Counter =0;
listOfAccountsPerPage = new List<Account>();
}
}
}
}
But I want each account in a list in each row. Any help?