aspose file tools*
The moose likes JSF and the fly likes line break using <h:outputText> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "line break using <h:outputText>" Watch "line break using <h:outputText>" New topic
Author

line break using <h:outputText>

Murali Pen
Greenhorn

Joined: May 23, 2006
Posts: 28
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?


Murali
SCJP,SCBCD,SCWCD
H Jetly
Ranch Hand

Joined: Aug 26, 2010
Posts: 41

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


Harsh Jetly
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15629
    
  15

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Murali Pen
Greenhorn

Joined: May 23, 2006
Posts: 28
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

Joined: Jun 25, 2001
Posts: 15629
    
  15

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: line break using <h:outputText>
 
Similar Threads
Double Page break
Safari - TypeError on first submit
ignore new line character
escape attribute in h:outputText component
inserting line break in <h:outputText> value