• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

line break using <h:outputText>

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Tomcat Server Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27762
196
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 27762
196
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
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!
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic