File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes JSF Expression Language and HTML    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Expression Language and HTML    " Watch "JSF Expression Language and HTML    " New topic

JSF Expression Language and HTML

Alex Balaban

Joined: Oct 10, 2008
Posts: 6
We have data stored in the database as text strings with embedded HTML tags (like links, bold characters, etc.). It get retrieved just fine, until it is inserted into XHTML page using EL expression syntax #{expression}. EL escapes all HTML special characters, which results in displaying it as plain text on XHTML page.

Is there any way how to disable this default JSF EL behavior - coersion rule? Maybe overwrite some class?


Alex Balaban

Joined: Oct 10, 2008
Posts: 6
Actually I can answer that myself....
The answer is to use JSF tag <hutputText value="#{reference}" escape="false"/> and set that escape to false.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

Just as a general precaution, however, I don't recommend having the backing layer emit display elements (HTML). There are times when it's necessary and I'm presently working on an app that does so. But that's because the app uses an HTML editor to input and display data (rather like the one that JavaRanch uses for postings).

I've seen - and suffered with - a number of webapps that output table rows with tags in them and committed various other offenses. It tends to be a real pain, since sooner or later there always seems to arise a need for just the data without the HTML. And having the display come from 2 different layers (JSF and Java code) can make both predicting output and finding what to change a real game of hide-and-seek.

So unless the HTML formatting is part of the backing data itself, I strongly urge that you put all the HTML (and CSS references) on the JSF pages, not in the backing beans.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: JSF Expression Language and HTML
It's not a secret anymore!