Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing formatted text to the user

 
John Tannel
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Tannel
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic