In my controller I have a map of integers and strings which I want to display as checkboxes.
The controller:
public Map<Integer, String> xmlCatalogsMap {get;set;}
public Set<Integer> xmlCatalogsKeys {get;set;}
public void getXMLCatalogs() {
String sql = 'SELECT BOID__c, Name FROM ZXMLCatalogs__c ORDER BY Name';
List<ZXMLCatalogs__c> result = Database.query(sql);
Map<Integer, String> xmlCatalogsMap = new Map<Integer, String>();
for (ZXMLCatalogs__c c : result) {
xmlCatalogsMap.put(Integer.valueOf(c.BOID__c), c.Name);
}
Set<Integer> xmlCatalogsKeys = xmlCatalogsMap.keySet();
}
getXMLCatalogs()
is called from constructor.
Now I want to display a checkbox for each integer/string pair. Integer/key should be the checkbox value and the string should be the label:
<apex:repeat value="{!xmlCatalogsKeys}" var="i">
<apex:pageBlockSectionItem>
<apex:inputCheckbox label="{!xmlCatalogsMap[i]}" value="{!i}" html-name="CatalogId" />
</apex:pageBlockSectionItem>
</apex:repeat>
I read how to display map on vf page in salesforce and How to reference a map's keySet() and individual map elements within Visualforce? Get 'Unknown function' error
When I compile with Sublime/Maven I always get the below error without line number:
Unknown property 'i'
Why can't I use i
(or any other variable name) as a variable?
Set<Integer> xmlCatalogsKeys = xmlCatalogsMap.keySet();
you should reinitialise the variable here. You have assign the valuesxmlCatalogsKeys = xmlCatalogsMap.keySet();
Set<Integer> xmlCatalogsKeys = new Set<Integer>(xmlCatalogsMap.keySet());
?apex:inputCheckbox