You need to sign in to do that
Don't have an account?
Ethan Hotz
Rendering a table with data from a nested map within a wrapper class
I'm trying to render a table using values from a list of a wrapper class, which contains a Map<String, Map<Date, Integer>> for each instance.
The VF:
And the relevant part of the controller. This method is called for each wrapper class instance whenever I press the Display Data button:
As is, the page returns a map key null not found error. The weird thing is, whenever I enable the
line, the table renders fine, except with null keys instead of the current page's case ID. I've probed most of my code with debug logs showing that the map seems to be populated as it should, so I have no idea what could be causing the page to fail.
The VF:
<apex:pageBlock > <apex:commandButton action="{!displayData}" Value="Display Data" reRender="tableBlock"/> </apex:pageBlock> <apex:pageBlock id="tableBlock"> <apex:pageBlockTable value="{!dummyList}" var="dummyVar" > <apex:column headerValue="Developer"> </apex:column> <apex:repeat var="week" value="{!formattedWeekList}"> <apex:column headerValue="{!week}"> </apex:column> </apex:repeat> </apex:pageBlockTable> <apex:repeat var="dev" value="{!userList}"> <apex:pageBlockTable value="{!dev.projectMap}" var="project" id="userTable" rendered="{!tableVisible}"> <apex:column headerValue="{!dev.userName.name}"> <apex:outputText >{!project}</apex:outputText> </apex:column> <apex:repeat value="{!dev.projectMap[project]}" var="date"> <!-- This is ID'd as the cause of the null map key --> <apex:column headerValue="0" > <!-- Placeholder value --> {!dev.projectMap[project][date]} </apex:column> </apex:repeat> </apex:pageBlockTable> </apex:repeat> </apex:pageBlock>
And the relevant part of the controller. This method is called for each wrapper class instance whenever I press the Display Data button:
public void checkData() { projectMap = new Map<String, Map<Date,Integer>>(); Set<WeeklyProjectStats__c> querySet = new Set<WeeklyProjectStats__c>(); Map<ID, Set<WeeklyProjectStats__c>> queryMap = new Map<ID, Set<WeeklyProjectStats__c>>(); for (WeeklyProjectStats__c item : projectList) { //Create new list, if caseid != this.case, add querySet.add(item); if (querymap.containsKey(item.Case__c)) { Set<WeeklyProjectStats__c> innerset = queryMap.get(item.Case__c); innerset.add(item); queryMap.put(item.Case__c, innerset); } else { Set<WeeklyProjectStats__c> tset = new Set<WeeklyProjectStats__c>(); tset.add(item); queryMap.put(item.Case__c, tset); } } //if (!queryMap.containsKey(TeamAllocationController.caseID)) queryMap.put(TeamAllocationController.caseID, null); if (queryMap.isEmpty()) { Map<Date,Integer> tMap = new Map<Date,Integer>(); for (Date week : TeamAllocationController.weekList) { tmap.put(week, 1); } projectMap.put('No projects assigned to this user.', tMap); return; } for (ID project : queryMap.keySet()) { Map<Date,Integer> innerMap = new Map<Date,Integer>(); for (Date week : TeamAllocationController.weekList) { Integer hours; WeeklyProjectStats__c tempStats = getListItem(querySet, project, week); if (tempStats == null) { hours = 0; } else { Set<WeeklyProjectStats__c> tset = queryMap.get(project); WeeklyProjectStats__c tStat = getListItem(tset, project, week); hours = (Integer)tStat.AssignedHours__c; } innermap.put(week, hours); } projectMap.put(project, innerMap); } } public WeeklyProjectStats__c getListItem(Set<WeeklyProjectStats__c> statList, ID project, Date week) { for (WeeklyProjectStats__c item : statList) { if (item.Case__c == project && item.Week__c == week) return item; } return null; }
As is, the page returns a map key null not found error. The weird thing is, whenever I enable the
if (!queryMap.containsKey(TeamAllocationController.caseID)){ queryMap.put(TeamAllocationController.caseID, null); }
line, the table renders fine, except with null keys instead of the current page's case ID. I've probed most of my code with debug logs showing that the map seems to be populated as it should, so I have no idea what could be causing the page to fail.
I guess the crux of the issue seems to be: why is the table rendered when a key is manually added on one line(at {1}), but not rendered when I do so on another line(at {2})?