[SalesForce] Use CONTAINS in Visualforce Page Map

I have an apex:pageblocktable in VF Page with 2 columns. The 2nd column is displayed from a map.

<apex:pageBlockTable value="{!noZips}" var="Zip">
<apex:column value="{!Zip.ZipCode}" headerValue="Name"/>
<apex:column value="{!mapZipLeadsCount[Zip.ZipCode]}" headerValue="Lead Count"/>
</apex:pageBlockTable>

The above gives error, when the Map doesn't contain that zipCode. Can we use CONTAINS KEY in Visualforce page to check for the key existence? How?

Also, I tried to put the zipcodes in a list (zipList in the controller) and checked if the list CONTAINS the key (code below). Even this fails.

<apex:pageBlockTable value="{!noZips}" var="Zip">
<apex:column value="{!Zip.ZipCode}" headerValue="Name"/>

<apex:column value="{!IF(CONTAINS(zipList,Zip.ZipCode),mapZipLeadsCount[Zip.ZipCode],0)}" headerValue="Lead Count" />
</apex:pageBlockTable>

Best Answer

I've hit this in Visualforce too and the only solution I've found is to ensure (in the controller) that the map does contain all the key values.

In your case before you populate the actual counts in the controller you could initialise the count for every ZipCode to zero:

for (Zip z : noZips) {
    mapZipLeadsCount.put(z.ZipCode, 0);
}

and then this Visualforce will just work unmodified:

<apex:column value="{!mapZipLeadsCount[Zip.ZipCode]}" headerValue="Lead Count"/>