• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TextArea String formatting issue

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am saving the content of <t:textArea> as a String which has line break, et cetera, in the database and when I am retrieving it is displaying as a one String. String is not shown as entered preserving the line break. I am using JPA and in the backing bean I am using String. In the mysql database, I tried VARCHAR, and LONGTEXT. Database String is showing fine with proper line break.

Could you please suggest your though on this.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't say what "showing" means. So my guess is that you are just displaying the string as text in HTML, which of course normalizes whitespace by removing newline characters or replacing them by a single space.

You don't say what a "database string" is and how it differs from a string which you save in the database. Sorry, I can't guess anything about that.

You don't say whether you looked in the database to determine whether the newlines are preserved by the process which puts the strings into the database. So my guess is that you haven't. You should do that, so that you know whether to fix the process which puts the strings into the database or the process which gets them out of the database and displays them.

These are only my thoughts, since you haven't really provided many details about the problem.
 
Manju Singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay, let me more clear on this. here is the text that I want to save in DB, entered in t:textArea-

<h:inputTextarea value="#{discussion.contents}" ></h:inputTextarea>

Line1, this is test string on line one.

This is test string on line second.



I persist above text in mysql db using entityManager.persist(obj). I have a setter/getter for contents of String type in POJO(entity class) and CLOB in database. I am not doing any special processing for this. When, I browse the database table it shows as it is entered,preserving the next line, as shown below -

Line1, this is test string on line one.

This is test string on line second.




But, when I display this text in browser it is displaying as one string as shown below -

Line1, this is test string on line one. This is test string on line second.



Any idea, how to display the text in browser as entered by user preserving the next line.

Thanks for your help.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When, I browse the database table it shows as it is entered, preserving the next line,



I'm not sure how you can see that in a table, but I'll take your word on it.

In your inputTextArea component, how many rows are you showing? <h:inputTextarea cols="?" rows="?" /> I don't see where you have specified that in your sample code.

Any idea, how to display the text in browser as entered by user preserving the next line.



Assuming you are just outputting the text to the browser, there is a HTML tag for preserving the formatting of text in a HTML document.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Manju Singh wrote:okay, let me more clear on this... when I display this text in browser it is displaying as one string as shown below -


Sorry, using the word "display" isn't any clearer than using the word "show". You still haven't said anything about the context in which you display the text. And I already pointed out how HTML handles whitespace in text, and you didn't say that didn't apply to your text. So I expect it does.
 
reply
    Bookmark Topic Watch Topic
  • New Topic