[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Display formatted output in JSF

Posted on 2009-04-02
2
Medium Priority
?
2,705 Views
Last Modified: 2013-11-24
I have a web application that uses jsf.  My form allows a user to enter paragraphs into an h:inputTextarea component, and they can enter carriage returns and it saves the formatting correctly into the database.  After saving and closing the form, they can open that form back up in read mode to see what they had written.  I am using h:outputText to display their paragraphs, but outputText doesn't display the carriage returns.

When the user opens the form in edit mode, the carriage returns correctly display in the h:inputTextarea.  But what can I use in JSF to preserve the format of their data while in read mode?
<h:inputTextarea style="width:700px;height:100px;" value="#{paragraph.bodyText}" rendered="#{bean.mode='Edit'}"/>
 
<h:outputText value="#{paragraph.bodyText}" rendered="#{bean.mode='Read'}"/>

Open in new window

0
Comment
Question by:chuckie474
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Assisted Solution

by:Kadhiravan
Kadhiravan earned 200 total points
ID: 24059246
You can use h:outputFormat to save the formatting. This will render the exact formatting in read mode.

Refer the following link on how to use the h:outputFormat.

http://www.jsftoolbox.com/documentation/help/12-TagReference/html/h_outputFormat.html
0
 

Accepted Solution

by:
chuckie474 earned 0 total points
ID: 24063398
That didn't work for me - it still showed all the lines running together.

But I ended up figuring out a solution:

I have a backing bean that I used to display the text, and I called a convertClobToString method to get the string from the Oracle clob.  In the conversion, the clob stores its carriage returns as "\n".  JSF doesn't know how to translate \n in an h:outputText, so I have to convert the \n to and html <br>.  So now I have two properties on my backing bean:

public String bodyText;
public String bodyTextDisp;

When I pull the data from the database, I store the values into the backing bean.

bodyText = convertClobToString(oracleClob);
bodyTextDisp = bodyText.replaceAll("[\n]", "<br>");

So now, in my JSF, I can use the bodyText field for the inputTextArea and the bodyTextDisp field for the outputText.  Because the bodyTextDisp now has <br> tags, I have to add an escape="false" tag to render the html properly.

<h:inputTextarea style="width:700px;height:100px;" value="#{paragraph.bodyText}" rendered="#{bean.mode='Edit'}"/>
 
<h:outputText escape="false" value="#{paragraph.bodyTextDisp}" rendered="#{bean.mode='Read'}"/>

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question