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

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: 28321
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
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: 28321
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
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!
 
Not so fast naughty spawn! I want you to know about
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic