Reputation: 293
I am developing simple page using JSF richFaces. I displayed file content into textArea using tinyMCE.
The file have more number of lines. But tinyMCE editor show all content in single line .
Original File content is : sample.txt
This
is
tiny MCE editor
related doubt
I read the file content using the follwing code
String content = org.apache.commons.io.FileUtils.readFileToString(fileName);
System.out.println("File Contnet is : " + content);
fileBean.setFileContent(content);
System.out.println show the content as line by line. But the editor shows the content in single line like
This is tiny MCE editor related doubt
Help me. Thanks in advance.
Upvotes: 1
Views: 1782
Reputation: 1684
The problem is that the file content you have is "plain text" while TinyMCE is designed to edit HTML.
In HTML, whitespace, including line breaks are ignored. As such, in the editor, you will see a single line of text.
One approach to solve this would be to parse the content prior to setting it in the editor and wrap the lines in Paragraph tags. For example,
<p>This</p>
<p>is</p>
<p>tiny MCE editor</p>
<p>related doubt</p>
To do this, you could use the onBeforeSetContent Event on the editor. The documentation on the event has an example of manipulating the HTML.
Assuming you are then planning to store the HTML in the backend, then there is no need to strip this HTML out when you save the content. If you aren't then the question is why you are using TinyMCE and not a simple TextArea.
Upvotes: 2