File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes introducing line breaks using bean:write or c:out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "introducing line breaks using bean:write or c:out" Watch "introducing line breaks using bean:write or c:out" New topic
Author

introducing line breaks using bean:write or c:out

geofrey pony
Greenhorn

Joined: Jul 18, 2006
Posts: 15
I have the following code for a Form

public class MyForm extends ValidatorActionForm{
private String receiptContent;
//getter setter available for this attribute
}

I have an Action class which sets a string onto this attribute present in MyForm correctly.The string however is like,

StringBuffer buffer = new StringBuffer();
buffer.append("firstName :"+firstName+"\n");
buffer.append("middlename :"+middlename+"\n\n");
buffer.toString();

with lot of \n or <br /> for generating appropriate display (read only).

So, if I then use bean.write() or c ut in my JSP to write this attribute present in MyForm, it writes everything in one line.
i.e ignores the \n or <br />altogether.
I tried replacing \n with <br /> also trying > br / < etc. No luck.

It seems to simply be considering everything as characters and ignoring the line breaks completely.

Please suggest how to go about this.

Thanks in advance.
geofrey pony
Greenhorn

Joined: Jul 18, 2006
Posts: 15
Resending, picked a few characters wrongly,

I have the following code for a Form

public class MyForm extends ValidatorActionForm{
private String receiptContent;
//getter setter available for this attribute
}

I have an Action class which sets a string onto this attribute present in MyForm correctly.The string however is like,

StringBuffer buffer = new StringBuffer();
buffer.append("firstName :"+firstName+"\n");
buffer.append("middlename :"+middlename+"\n\n");
buffer.toString();

with lot of \n or <br /> for generating appropriate display (read only).

So, if I then use bean.write() or c: out in my JSP to write this attribute present in MyForm, it writes everything in one line.
i.e ignores the \n or <br />altogether.
I tried replacing \n with <br /> also trying '<' br / '>' etc. No luck.

It seems to simply be considering everything as characters and ignoring the line breaks completely.

Please suggest how to go about this.

Thanks in advance.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Replace the \n with <br> as you tried before, but this time specify filter="false" in your bean:write tag. Exmaple:

You can also use the <cut> tag by specifying escapeXml="false".
[ May 09, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
firstName and lastName should be set in the form and the jsp (the view part of MVC) should do the visual/html formatting.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: introducing line breaks using bean:write or c:out