*
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
Author

Printing formatted text to the user

John Tannel
Greenhorn

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: 16145
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
John Tannel
Greenhorn

Joined: Dec 17, 2010
Posts: 23
Tim,

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.

John
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing formatted text to the user