You need to sign in to do that
Don't have an account?

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.name} : {!map.custom}
</apex:repeat>
Controller
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?
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.
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.
check this out:
http://techsahre.blogspot.com/2011/03/using-map-in-your-vf-pages.html
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
hi,
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.
Thanks