• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

line break using <h:outputText>

 
Murali Pen
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?
 
H Jetly
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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18108
51
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
Saloon Keeper
Pie
Posts: 18108
51
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic