This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Struts and the fly likes Line breaks in html:textarea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Line breaks in html:textarea" Watch "Line breaks in html:textarea" New topic

Line breaks in html:textarea

Tim Storms
Ranch Hand

Joined: Apr 27, 2006
Posts: 64
Hi, I'm having troubles showing the line breaks entered in a html:textarea.

When I submit the form with the html:textarea, an action servlet saves all form data in a bean. When the flow of my forms is completed, an overview page is shown. All the variables of the bean are shown here. Now here's the problem. The line breaks entered in the html:textarea are removed. All the text is shown as one big line.

I found a two year old article on this forum, where somebody advised to use the filter attribute of the bean:write tag (this is used in my overview page). But this doesn't solve my problem. All the text is still on one line.

Is there something I can do about it?

SCJP 1.5, SCWCD 1.4, SCBCD 5
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Please read this link on the html <textarea> tag. It explains that if you specify wrap="hard", it will cause line breaks to be included in the text when the form is submitted.

If you're using <html:textarea>, though, there is a problem. Struts does not accept a "wrap" attribute to pass on to the rendered html tag.

You have two options:

1- Use the regular HTML tag <textarea> instead of <html:textarea> As long as the name attribute of the <textarea> tag matches what you would have specified as the property attribute of the <html:textarea> tag, Struts will still populate your ActionForm with the value. If you need to display a previously entered value in the field, you will have to use a scriptlet or EL expression in the "value" attribute.

2-Create your own custom tag that extends the <html:textarea> tag that will pass the wrap attribute through to the rendered html.

Consultant, Sima Solutions
Tim Storms
Ranch Hand

Joined: Apr 27, 2006
Posts: 64
Thanks for your reply. I tried the wrap attribute, but it didn't solve the problem in my application.

I used in the setter method of my form bean and that did the trick.

I preferred your way of solving the problem, but this is the only way IE actualy shows the line breaks.
I agree. Here's the link:
subject: Line breaks in html:textarea
It's not a secret anymore!