• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF Expression Language and HTML

 
Alex Balaban
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17993
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic