Escaping XML in XML in JSFPosted by Roger Keays, 14 June 2008, 1:26 AM |
Recently I discovered that my RSS feeds were broken because of the Latin characters in the content. JSF's h:outputText unhelpfully converts these to HTML entities which are invalid in XML files such as RSS feeds. Even with escape="false", the HTML markup still breaks the feed. Short of writing an XML renderer for h:outputText, I came up with the following putrid hack. It is an ugly stain on my otherwise beautiful code, a parasite to perfection, a car wreck on the corner of Coro Drive and Moggill Road, a pile of puppy poo on the pavement. But it works...
<title>
<h:outputText value="<![CDATA[" escape="false"/>
<h:outputText value="${item.title}" escape="false"/>
<h:outputText value="]]>" escape="false"/>
</title>
Repeat for all output in your XML/RSS templates.
| << Spampot test results | Back to Blog | Using c:set in Facelets >> |
Comment posted by: Ryan Lubke on 28/07/2008 12:07:50 PM
I'm curious, which impl/version of JSF were you using when you hit this issue?
Comment posted by: Roger Keays on 28/07/2008 12:10:35 PM
Mojarra 1.2.04_p02
Comment posted by: Ryan Lubke on 29/07/2008 1:12:20 AM
Might give 1.2_09 a shot. We added a config parameter called com.sun.faces.disableUnicodeEscaping which may resolve this issue.
See the release notes [1] for details.
[1] http://tinyurl.com/5txnpo