HTML break in string from java bean
[nobr]I have a JSP page which uses a datatable to show the properties of a number of objects that are passed from an array. Is it possible for a string property in an object to have a line break which will appear as a break on the interpreted HTML?
Say I have a string:
String str ="WORD";
and I want to append something to it, but have it force a line break, I've done the following:
str +="\n\n" +"WORD2";
On the JSP this will show up as:
WORDWORD2
instead of :
WORD
WORD2
The \n doesn't appear. I've tried uisng
but this shows up in the jsp page as a string
WORD
WORD2
Does anyone know how I can accomplish this?
Thanks[/nobr]
[810 byte] By [
mon.goosea] at [2007-11-27 8:55:09]

# 3
The CSS suggestion was helpful but still hasn't given me a full solution.
I'm receiving differing results for the white-space property when I set it in a JSF page.
I set about trying out the property in a simple HTML page as I do with all new CSS properties I need to figure out.
I need to set white-space: pre-wrap; since this will allow for line breaks to appear as needed as well as wrapping the text in the container.
As it turns the browser compatibility for this property is very iffy so I've used this as a CSS rule:
.gen
{
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
I tried a test in a few browsers and this CSS rule works perfectly to format the text the way I want. The problem is, when I set the same rule in a JSF page using styleClass="gen" in an h:outputText tag I don't get the correct formatting.
In firefox the text comes out wrapped as it should, and even breaks lines, but condenses multiple line breaks.
Opera on the other hand doesn't preserve whitespace at all.
I though there might be a problem with the way I have the text outputted, but I checked the source of the generated page and it has all of the formatting from the original string such as multiple line breaks.
I'm a little puzzled, since I haven't yet had a JSP / plain HTML discrepency in the rendering of CSS properties.
Any help would be appreciated.
# 5
I could easily have each line per block of text be included in a single index of an array or arrayList if this is all that I need to do.
I can see where you're coming from, if each row is a line of the block, then empty lines would register as empty rows.
If you can explain further that would be helpful.
I was hoping for a more elegant solution though. I'm frustrated with the fact that the CSS isn't behaving the way it does in a pure HTML page.