Check if map/set contains element in Salesforce VisualForce page

Posted on 17-05-2013 13:09 by graham
If you want to check if an element exists in a set, or if a key exists in a map, on your VF page, you might be disappointed that this is not possible.

What you need to do is to have a value for every key in a map, and then check the value for this key. For example:
class PageController
public Map<String, Boolean> validUsers { get; private set; }

And then on your VF page:
<apex:image url="{!URLFOR($Resource.SomeResource, flag.gif')}" rendered="{!validUsers['John'] == true}" />


Add comment

Has this tutorial been helpful to you? Or do you see anything wrong? We appreciate your opinion!
Your comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems