[SalesForce] Unable to display map of in repeat

I have a map Map of String(key) and List(value). The list is a list of a wrapper class object

I initialize the map:

map.put('x', new List);

map.put('y', new List);

I populate the map like:

map.get('x').add(new WrapperClass(a, b, c));

When I do a system.debug on this map, it shows me the keys x and y and their values (which is a list). The problem however comes when displaying this map on a visualforce page in an apex repeat.

I want to create pageblocks for each key in the map. These pageblocks will contain pageBlockTable which will show columns based on the List (which is the value for the key in the map).

So something like this:

<apex:repeat value="{!myMap}" var="key">
  <apex:pageBlock>
     <apex:pageBlockTable value="{!myMap[key]}" var="listItem">
        <apex:column>
           <apex:outputText value="{!listItem.a}"/>
        </apex:column>
        <apex:column>
           <apex:outputText value="{!listItem.b}"/>
        </apex:column>
        <apex:column>
           <apex:outputText value="{!listItem.c}"/>
        </apex:column>
     </apex:pageBlockTable>
  </apex:pageBlock>
</apex:repeat>

When I run the page, it does not show me anything, not even empty page blocks. However the system debug shows the populated map and the populated list.

I did an inspect element for a possible javascript issue but its clean.

Does anyone have any idea why my pageblock and the table are not being displayed?

Thanks for the help.

Best Answer

This controller:

public class MyController {
    public Map<String, List<String>> myMap {
        get {
            return new Map<String, List<String>>{
                    'abc' => new List<String>{'123', '456'},
                    'def' => new List<String>{'654', '321'}
                    };
        }
    }
}

and page:

<apex:page controller="MyController">
    <apex:repeat value="{!myMap}" var="key">
        <apex:pageBlock >
            <apex:pageBlockTable value="{!myMap[key]}" var="listItem">
                <apex:column value="{!listItem}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:repeat>
</apex:page>

produces the expected repeated page block tables (as the apex:repeat automatically iterates over the map keys).

So I think your problem lies in the code that builds myMap or in the code that exposes it from your controller and you have not posted that code.