• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

line break using <h:outputText>  RSS feed

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to output text in database that contains line breaks using <h:outputText> tag.

I tested the following code:

<h:outputText value="1) first line <br/> 2) second line" escape="false" />;

The output it displays the line break correctly on the web page.

1) first line
2) second line

However when the same text in the value attribute is coming from a bean property, line break is not rendered.

<h:outputText value="#{myBean.myText}" escape="false" />

Output on web page:

1) first line <br/> 2) second line

Can someone help?
 
Ranch Hand
Posts: 41
Google Web Toolkit Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this has something to do with the JSF lifecycle, the values if you hard code them are attached to the component tree before applying values that come from the managed bean..
So I think writing a phase listener would help, I am not too sure though
 
Bartender
Posts: 19668
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would take a look at the actual data in the database.

If you're using outputText escape=false, the following should display with linebreaks:


However, if the data looks like this:


Then the "escape" attribute won't help, because it was escaped in the data itself.

Now in real-world terms, it would have been better for the data to be in a div using orderedList (ol) HTML tags, but that's probably not under your control.
 
Murali Pen
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, you are right. I did verify the data and it was escaped there. When I changed it to <br/>, it worked.
 
Tim Holloway
Bartender
Posts: 19668
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just realized that the "code" tags didn't render my second example right.

The actual value should have been "&lt;br/&gt;".

Anyway, glad to see you resolved it!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!