• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Line breaks in html:textarea

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Storms
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!