+ Start a Discussion
kcussenkcussen 

Repeating over maps in vf using dates as the key

Good day all,

 

I've got a visualforce page where I need to display lists of a variety of custom objects based on the date. Hence I've set up most of my custom objects as maps similar to the following:

 

Map<Date, List<dailyScheduleWrapper>> dailyScheduleWrappers

 

As long as the Maps are local variables within the controller, I'm not having any issues displaying them. However, if I try to display the maps from a wrapper class inside the controller I start getting the following error: 

 

Visualforce Error

 

Help for this Page


Map key Sun Oct 14 00:00:00 GMT 2012 not found in map

Error is in expression '{!wsw.dailyScheduleWrappers[td]}' in component <apex:repeat> in page weekly_schedule

 

I understand that it's looking for '2012-10-14 00:00:00' as the key, not 'Sun Oct 14 00:00:00 GMT 2012'. I've run through tests to establish the format for the key during creation is 'YYYY-mm-dd hh:mm:ss'. However, the key is the same for the maps local to the controller and they display without any issues - so I'm at a bit of a loss. 

 

 

 

<apex:outputPanel id="wsDisplay">
<apex:repeat value="{!weeklyScheduleWrappers}" var="wsw"> 
<table border="1">
<tr>
<td>
<table border="1">
<tr>
<apex:repeat value="{!testDates}" var="td">
<td>

<!-- This throws the above error -->
{!wsw.dailyScheduleWrappers[td]}
</td> 
</apex:repeat>
</tr>
<tr>
<apex:repeat value="{!testDates}" var="td">
<td>

<!-- This works fine -->
{!allResourceWrappers[td]}
</td>
</apex:repeat>
</tr>
</table>
</apex:repeat>
</apex:outputPanel>

 

and the controller / classes...

 

public with sharing class WeeklyScheduleController {

...

public Map<Date, List<resourceWrapper>> allResourceWrappers { get; set; }

public List<WeeklyScheduleWrapper> weeklyScheduleWrappers { get; set; }

...

 

public with sharing class WeeklyScheduleWrapper {

 

public Map<Date, List<dailyScheduleWrapper>> dailyScheduleWrappers { get; set; }

 

And if someone could let me know how to tag code so it embeds correctly, that would be fantastic. Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
APathakAPathak

Hi,

Why not use map definition as :

 

Map<String, List<dailyScheduleWrapper>>

 

The String would be the date converted to string date type you are using in your map. This way we can be sure of that date format is fixed. For ex- formatGmt function.