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]
# 1
My above post has lost some of its original formatting. On the last note I meant to say I tried manually entering the HTML br tag and this shows up on the jsp page as a string, but no break.
mon.goosea at 2007-7-12 21:15:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
http://www.w3.org/TR/CSS21/text.html#propdef-white-space
RaymondDeCampoa at 2007-7-12 21:15:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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.

mon.goosea at 2007-7-12 21:15:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
If you could somehow rather use an ArrayList instead of a String, you could easily do this by using an imbeddded datatable.
lordfeia at 2007-7-12 21:15:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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.

mon.goosea at 2007-7-12 21:15:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Why don't you use < br > instead of \n? The \n is not a HTML tag and therefore it only works if you parses this piece of text as preformatted text -which is a ugly workaround to introduce linebreaks in HTML tbh.
BalusCa at 2007-7-12 21:15:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Using a br tag is the first thing I tried. The problem is that outputing a string from a javabean which contains br tags automatically converts the br tags to be displayed and not act as proper html tags.

I would imagine there is an escape to force the generated page to create true br tags

mon.goosea at 2007-7-12 21:15:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
h:outputText has an escape attribute. If it is set to false, then the HTML entities like < and > won't be escaped into & lt; and & gt; anymore.
BalusCa at 2007-7-12 21:15:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...