• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

HOw do I replace new lines with <BR> tags?

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I"m using MyFaces 1.1.5 with Tomahawk 1.1.7. Does anyone know how I can replace carriage returns ("\n" characters) with
so that my text is output and properly formatted ? The <PRE> tag is not an option as it doesn't allow styling of the text within it. Currently I am wrapping the text in a span with a particular class and then using Javascript to find all instances of that class and replace the HTML within it. A ridiculous hack, but there is surprisingly no help for this subject online.

Thanks, - Dave
 
Saloon Keeper
Posts: 28410
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a rule, I don't like to generate HTML in the code. Wherever possible, I prefer to keep the display stuff in the display and the logic stuff in the logic components. But there are times when this isn't practical. For example, I have an app which allows people to edit, store, and display formatted text on web pages. It uses a RichFaces HTML editor control, so the raw data is in HTML form (which is still better than hard-coding HTML in java code).

To display that kind of stuff, you can use the <h:outputText escape="false" value="...."/> construct. If your text contains end-of-line characters, you can use a string search-and-replace function to substitute "<br/>" tags and output the results using outputText.

Earlier versions of JSF did not handle intermixing raw HTML and JSF tags very well. It's much better these days, but you'll still end up with tidier, more portable displays if you minimize the HTML and use the JSF equivalents.
 
Greenhorn
Posts: 10
Netbeans IDE Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're using a backing bean to get your text, just use string replacement to replace "\n" with "<br />".


Then use escape = false in your outputText field.

* This answer might come a bit late for the OP. But google brought me here, so it might help someone else. *
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tom mmeke wrote:If you're using a backing bean to get your text, just use string replacement to replace "\n" with "<br />".


Then use escape = false in your outputText field.

* This answer might come a bit late for the OP. But google brought me here, so it might help someone else. *



It helped me out, thank you. I did however end up with a bit of a doubt. What do you mean by "entity" on this line?



 
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic