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

Printing formatted text to the user

John Tannel

Joined: Dec 17, 2010
Posts: 23
Right now, if a user enters text into a text box and saves that information, when it is redisplayed to them or another user the formatting is, as expected, wrong.

Newlines, spaces, etc all get jumbled into a single space as per the html standard.

For example if they type:

it comes out as:

Is there an easy way to remedy this? My first thought it to pass the text through a filter that replaces all newlines with an html break element but I feel JSF must provide some easier solution. My second thought may be to just display the text using another textArea but leave it disabled so as to only display the information, but this seems quite backwards.

Does anyone have any better ideas for me?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

JSF is at the mercy of HTML on this one.

You can use a rich text editing extension JSF tag, but most of those simply allow the editing and display of HTML, so you'll still be at the mercy of HTML's restrictions, just able to handle fancier formats such as boldface and italics.

An IDE is no substitute for an Intelligent Developer.
John Tannel

Joined: Dec 17, 2010
Posts: 23

I ended up just filtering newlines and carriage returns to <br/> and then turning off escape on the outputText. It's not perfect, but it looks pretty darn good. It accomplishes what we want - allowing the user to have paragraphs and create crude lists in the textbox.

I agree. Here's the link:
subject: Printing formatted text to the user
jQuery in Action, 3rd edition