wood burning stoves 2.0*
The moose likes JSP and the fly likes Formating text in TextArea using EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Formating text in TextArea using EL" Watch "Formating text in TextArea using EL" New topic
Author

Formating text in TextArea using EL

Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
Hello;

I have the following code:

<textarea cols="" rows="50" name="emailList" style="width: 500; text-align: left;"><c:forEach var="email" items="${list.emailList}">${email},/n</c:forEach></textarea>

The problem is the list of elements get written in one long string. I would like each element to be on it's own line. Does EL have something like a println() that would do this for me? Is there some JSTL tag I should look into?

Thanks,

Luke


Luke
SCJP
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

The newlines should be in your markup. E.g.:


[ October 15, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
I tried that, however the new line symbols get printed as text:

luke@lukeshannon.com,/nlukeshannon@hotmail.com,/n
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

What does the View Source show?
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
<textarea rows="50" name="emailList" style="width: 500; text-align: left;">luke@lukeshannon.com,/n lukeshannon@hotmail.com,/n xxxxxx@auctionsfind.com,/n xxxxxx@auctionsfind.com,/n </textarea>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Remove the hard-coded "/n" characters
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
If I put a space in the text to be written directly after the comma, and remove the hard coded characters, I get a list of 2 emails by 2 emails. This is much better than a big long string.

Still not sure how to get them each on their own line, but this is close enough.

Thanks!

Luke
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

The generated JSP will preserve any newlines in the source. So you could also write:



If you want complete control over the format, write a formatting bean.
Luke Shannon
Ranch Hand

Joined: Sep 30, 2004
Posts: 239
A formatting bean... sounds interesting. I will look into that.

Thanks again.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Or, if the list is being provided by a controller servlet, the servlet could tack a pre-formatted block onto the request rather than the raw list.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Formating text in TextArea using EL
 
Similar Threads
ui:repeat or c:foreach in tr:panelAccordion
JSP 2.0 EL and html:options issue
Have the rules for EL in a JSP changed?
passing object from JSTL into applet
JSTL functions problem