0

How do I escape f:selectItems itemLabel to use HTML markup? Below is the code

<h:selectManyListbox 
    id="geographicLoc"
    value="#{handlerBean.selectedGeographicLoc}">
    <a4j:ajax event="change" render="citiesID" status="newState" />
    <f:selectItem 
        itemLabel="All &nbsp; All" 
        itemValue="All" itemEscaped="false"/>
    <f:selectItems 
        value="#{handlerBean.geographicLocList}" 
        itemEscaped="false"/>
</h:selectManyListbox>

The attribute itemEscaped is working for f:selectItem but not for f:selectItems.

In backingbean, geographicLocList is of type SelectItem list and I am trying to add  in java as below

final SelectItem selectItemS = new SelectItem();    
selectItemS.setLabel("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
                        + country.getStateDesc());
selectItemS.setValue(country.getStateCode());
geographicLocList.add(selectItemS);
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1661892
  • 103
  • 4
  • 13

1 Answers1

4

As per the <f:selectItems> tag documentation, you need the itemLabelEscaped attribute for this.

<f:selectItem ... itemEscaped="false" />
<f:selectItems ... itemLabelEscaped="false" />

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Sorry :( I missed mentioning in my post that I have tried this solution as well after referring the api docs but it did not work for me. Then I ran into one of your solutions(provided into see also section) on the same forum and there I found itemEscaped="false" option. But both did not work fr me. Do you see any issue in Java code for creating the SelectItem list? – user1661892 Jul 04 '15 at 06:05
  • It works for me. Consider posting a MCVE. The `itemEscaped` is for `` only. – BalusC Jul 04 '15 at 06:06
  • I see you're the one who migrated from JSF 1.x to 2.x and are also having other sort of trouble like that one with c:forEach. All in all I guess your webapp's runtime classpath is polluted. I'd sort that out first before continuing with code. – BalusC Jul 04 '15 at 06:11
  • I have updated all context-param and removed ajaxanywhere filter per your suggestion. Removed facelets jar from POM, added myfaces-api, myfaces-impl, tomahawk and JSTL jars. Updated my faces-config. Did a clean maven build. Not sure what else is making the classpath polluted :( – user1661892 Jul 04 '15 at 06:25
  • Old jars still in the deployment folder… – Kukeltje Jul 04 '15 at 07:19
  • I have only myfaces-api-2.2.7.jar myfaces-impl-2.2.7.jar, javax.el-api-3.0.0.jar, javax.servlet-api-3.1.0.jar, javax.servlet.jsp-api-2.3.1.jar, javax.servlet.jsp.jstl-api-1.2.1.jar, tomahawk21-1.1.14.jar. I am also upgrading richfaces to 4.5.5 version. Double checked but I do not see the older jars anymore :( Thanks for the reply! – user1661892 Jul 04 '15 at 07:55
  • I guess you're deploying to Tomcat. Servlet, JSP and EL APIs are already provided by Tomcat itself. Including them in the webapp anyway would result in classpath pollution in those classes. Get rid of them (in Maven terms, set the `` to `provided`) and retry. – BalusC Jul 04 '15 at 11:14
  • Yep I am deploying to Tomcat. I have them already in provided scope. – user1661892 Jul 04 '15 at 16:53