[SalesForce] How to escape a double quote in a Visualforce attribute

I would like a select option to appear in the page like this:

User and 2 "Reports To" Levels

but have not figured out how to escape the double quotes in a Visualforce attribute such as:

<apex:selectOption itemValue="2" itemLabel="User and 2 "Reports To" Levels"/>

How do I do this (without resorting to using a single quote instead)?

Best Answer

This can be done using the itemEscaped="false" attribute on the apex:selectOption tag. This will allow you to use HTML in the label text and render it into the page.

In your case, you want to use &quot; to produce the quote character in the label: User and 2 &quot;Reports To&quot; Levels.

<apex:selectList id="myElement" value="{!selectedValue}" size="1">
    <apex:selectOption itemEscaped="false" itemValue="2" 
        itemLabel="User and 2 &quot;Reports To&quot; Levels"/>
</apex:selectList> 
Related Topic