This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean:write and formatting text

 
Steven Tarsia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all. I pretty new with jsp pages and am having some problems formatting text using bean:write.
Our users can enter newlines in the description field, which is stored in the Db. Upon displaying this data, the newlines are ignored - they do show in the Db. I can wrap the bean in a <pre/> tag and this will show the entered newlines, but if no newlines are entered the description will show on one line. Without the <pre/> tag, the description shows neatly wrapping text (which I want), but does not show the newlines entered (which I need to show).

This shows the text neatly wrapping, but will ignore the newlines.
<bean:write name="x" filter="false"/>

This will show the newlines, but also shows text on one line if no newlines are entered.
<pre><bean:write name="x" filter="false"/></pre>

Is there a way to maintain the state of the description with the newlines and also not completely loose the inherent formatting?

Any help is appreciated and thanks in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64607
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Questions on Struts tags are best asked in the Struts forum. I've moved this post there for you.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One possible solution would be to have the action class that prepares this JSP scan the text and convert all new-line characters to "<br>". Then just display the text as you are now doing without the <pre> tag.
[ May 08, 2007: Message edited by: Merrill Higginson ]
 
Steven Tarsia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I modified the action page to make the necessary conversions. This worked for me. Thanks for pointing this struts greenhorn in the right direction.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic