Author | Message |
---|---|
jonathankroening
Posts: 39
|
Posted 11:08 Mar 12, 2013 |
How can I handle line breaks in the description field of my Create Project form? I want to make sure that if the user thinks there should be a new paragraph in the description that my data represents this formatting. Is there a standard way to preserve new line markers when using JDBC Architecture? |
cysun
Posts: 2935
|
Posted 11:23 Mar 12, 2013 |
Are you using PreparedStatement? |
jonathankroening
Posts: 39
|
Posted 11:38 Mar 12, 2013 |
Yes. |
cysun
Posts: 2935
|
Posted 12:23 Mar 12, 2013 |
Then new line characters should have been preserved. What error did you get? |
cysun
Posts: 2935
|
Posted 12:32 Mar 12, 2013 |
OK, I think I understand what you meant: the new lines entered in the input box are not displayed as new lines. This is because the description is displayed as HTML, which treats new lines as white spaces. There are several solutions for this: a) insert <br /> (or <p>) into the text before displaying it. b) display the text in a <pre> tag. c) use a Rich Text Editor like CKEditor. (c) is probably the best way. |
jonathankroening
Posts: 39
|
Posted 13:00 Mar 12, 2013 |
No error. If I return to the next line while typing out a description to make multiple paragraphs it is not reflected on the Project Page in the description of the project. Everything is on one line. I'm using <textarea> in my form. And then getParameter( "description" ) in the doPost method of my servlet. That string is then set in my PreparedStatement. In the MySQL table the new lines are preserved as are they if I do a test and call project.getDescription() from the servlet. Everything prints out fine. So the issue is in my displaying of the information in the JSP. I use ${project.description} and there the new lines characters seem to have been lost. My guess is that I might need to convert the "\n" into "<br/>" somehow. I tried a replace ${fn:replace(project.description, '\\n', '<br/>')} but it didn't work. |
jonathankroening
Posts: 39
|
Posted 13:01 Mar 12, 2013 |
Oh ok. Thanks. Just saw your post after posting my last reply. |
jonathankroening
Posts: 39
|
Posted 10:13 Mar 14, 2013 |
I found another solution for anyone out there wondering...
<p>${fn:replace(project.description, " ", "<br />")}</p>
This will replace the line breaks of the string with <br/> for html. For some reason using a replace function of "<br/>" for "\n" (remembering to escape the backslash character) wasn't performing a replace. But by simply returning to the next line in the JSP, the replace function recognizes the line break and replaces with html breaks. |