function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Iterating over a List of Maps in VisualForce?

Is it possible to iterate over a List of Maps? In the simplest form, a Map<String,String>... I want to be able to do the following in a visual force page (simplified):


VisualForce Page

<apex:repeat value="{!customMap}" var="map">
{!} : {!map.custom}





public someController
public List<Map<String,String>> customMap = null;

public getCustomMap()
if (customMap == null)
customMap = new List<Map<String,String>>();

customMap.add(new Map<String,String>{
'name' => 'Apple',
'custom' => 'Pie'

customMap.add(new Map<String,String>{
'name' => 'Banana',
'custom' => 'Cake'
return customMap;


 Would hopefully print something like...



Apple : Pie
Banana : Cake


 This is obviously not working for me, any suggestions or is this not possible right now?




Ron HessRon Hess

No this is not a feature of Visualforce. 


you must construct a data structure that holds the info that you require, and provides getter methods for the strings that you will display on the page


Thanks. I found another post where they explained this can be achieved through subclassing.  Makes sense after thinking about it.


Thanks for the response and help.

While this is not currently supported in Visualforce, it is something we're looking at adding in a future release.
can you please post code how you did subclassing?

Well, I don't have the exact code in front of me, but instead of loading a map for the value, you would use a custom object instead that has those values.


So in my example, i was trying to pass this to apex:repeat...


List<Map<String, String>> customMap = new List<Map<String,String>>();

... add maps to list ...


Instead, you'll want to do this...


List<myCustomObject> customObjects = new List<myCustomObject>();

... add custom objects to list ...



the object can be a simple class with those properties. Sorta tedious so I'm glad that they will be looking into adding this in the future.






is that a trick or a legitimate work around?

i only see two fields being brought over, i need 5



here is one that uses a list of maps of maps


controller info
    public List<productfamily__c> familys {get;set;}
    public Map<ID,LIST<Product2>> mapID_Prods  {get;set;}
 public Map<String,LIST<ProductComponent__c>> mapID_Components  {get;set;}

    <apex:form id="plist" >
            <apex:selectlist multiselect="false" size="1">
                  <apex:selectOptions value="{!fields}"/> 
            <apex:outputLabel style="font-weight:bold;" value="generate SOQL" ></apex:outputLabel>
            <apex:inputcheckbox value="{!doSql}" id="sqloutput" />

            <apex:datalist value="{!familys}" var="family" id="plistul" >
                <apex:inputCheckbox selected="false" />
                <apex:outputText value="{!}" />
                  <apex:datalist value="{!mapID_prods[]}" var="prod" >
                    <apex:inputCheckBox selected="false" />
                    <apex:outputText value="{!}" />
                    <apex:datalist value="{!mapID_Components[]}" var="comp" >
                            <apex:inputCheckBox selected="false" />
                            <apex:outputText value="{!}" />
            <apex:outputText value="Save"  id="freddy"/>
            <apex:outputText value=" testing" id="sometext"/>





i have some doubts regarding this. How can we get the selected checkbox values in controller. Do we need to use wrapper class in controller.


Because i am also doing the same functionality. List of Regions and List of countries. I have to map countries based on regions.

like Map<string, List<string>>. I want to get the selected checkbox regions and countries. Please suggest.