This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
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.
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.