aspose file tools*
The moose likes Struts and the fly likes bean:write and formatting text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean:write and formatting text" Watch "bean:write and formatting text" New topic
Author

bean:write and formatting text

Steven Tarsia
Greenhorn

Joined: May 08, 2007
Posts: 2
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

Joined: Jan 10, 2002
Posts: 61608
    
  67

Questions on Struts tags are best asked in the Struts forum. I've moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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 ]

Merrill
Consultant, Sima Solutions
Steven Tarsia
Greenhorn

Joined: May 08, 2007
Posts: 2
I modified the action page to make the necessary conversions. This worked for me. Thanks for pointing this struts greenhorn in the right direction.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean:write and formatting text