File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes adding new lines to TextArea form value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "adding new lines to TextArea form value" Watch "adding new lines to TextArea form value" New topic
Author

adding new lines to TextArea form value

Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

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

Joined: Jan 10, 2002
Posts: 61756
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Yahya Elyasse
Ranch Hand

Joined: Jul 07, 2005
Posts: 510

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

Joined: Jan 10, 2002
Posts: 61756
    
  67

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

Joined: Jul 07, 2005
Posts: 510

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

Joined: Jul 07, 2005
Posts: 510

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

Joined: Jan 10, 2002
Posts: 61756
    
  67

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
 
subject: adding new lines to TextArea form value