Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Expression Language and HTML    " Watch "JSF Expression Language and HTML    " New topic
Author

JSF Expression Language and HTML

Alex Balaban
Greenhorn

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?

Thanks

Alex
Alex Balaban
Greenhorn

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.


Alex
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSF Expression Language and HTML