This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

adding new lines to TextArea form value

 
Yahya Elyasse
Ranch Hand
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You probably all have posted messages on this forum.text is entered in textArea forms and when you type a new line it is automatically transfered with the textarea form value text...

i want to implement this same behaviour : i have a jsp page with a form having a textarea . when i submit the form i want to have the text formated so each typed new line is transfer as a <br> html tag with texarea value text.

is this possible ? how can i do it ?

thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would need to write code on the server to take the submission result and translate the line breaks to break tags if that's what you want to do. Or I suppose you could do it in the browser using Javascript in an onsubmit handler, but that seems a bit on the messy side.

Why would you want to do something like this on submission? Seems more produdent to do it as a formatting step when displaying the data rather than when it is submitted.
 
Yahya Elyasse
Ranch Hand
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and thnx for your reply,
it's important for my application to get input line by line so I can process it later...now if user types a new line in textArea how can the textarea form component know that ?
can you please show some server side code to do that ?
i appreciate a lot your help.
thnx
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by othman El Moulat:
it's important for my application to get input line by line


It depends what you mean by "line by line".

If by that you mean when the user enters a new line into the text area by hitting the Enter key, those will be reflected in the submitted value with line terminator characters. (Converting these to <br> tags isn't a great idea. Just leave the line terminators in order to demarcate the "lines").

If you mean the artificial soft-wrapping that occurs when the user reaches the width of the text area, that information is not available.
 
Yahya Elyasse
Ranch Hand
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends what you mean by "line by line".

If by that you mean when the user enters a new line into the text area by hitting the Enter key, those will be reflected in the submitted value with line terminator characters

this is exactly what i mean...but what are the line terminators look like ?(my html knowledge is basic).

Converting these to <br> tags isn't a great idea. Just leave the line terminators in order to demarcate the "lines"

then how can i get the input line by line...to separate lines i used the following :

supposing the exerciseText string contains <br> tags..what should i put in place of <br>?
thnx
 
Yahya Elyasse
Ranch Hand
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well to explain more what i want to do :

i will be entering a java program source code in the text area.. and then submit form .
i want to get this program code as parameter value and then be able to split it into a well formated text and i want later to process each line of the program seperately.
what is the best way to get a well formated java code text string in the standard format of java programs with seperate lines?

thnx
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but what are the line terminators look like ?(my html knowledge is basic).


Write a little servlet to inspect the data that you are getting from the text area. Check each character of the input. What do you find at the points where you used the Enter key in the text area?

then how can i get the input line by line...


By breaking on the line terminators. <br> is a markup artifiact that has nothing to do with backend data.

supposing the exerciseText string contains <br> tags..


How would those <br>'s get there? If you don't put them there, you don't have to worry about mnarkup.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic