This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JSF and the fly likes formatting a string from backbean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "formatting a string from backbean" Watch "formatting a string from backbean" New topic

formatting a string from backbean

Dura Hurtado
Ranch Hand

Joined: Feb 16, 2011
Posts: 120
Hi, when I try to format a string in a method, and recover it thougth :

<p> <h:outputText value="#{Content.load}"/></p>

and in the method:

result=result.substring(0, 10)+'\n'+result.substring(11, 20)+'\n'+result.substring(21, 30);

it shows in the browser:

bbbbbbbbbb bbbbbbbbb bbbbbbbbb

┬┐what way could I retrieve the next?





Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17423

HTML does not honor line breaks, so adding "\n" to a string won't work. You'd have to insert a line-breaking HTML tag such as "<br/>" or "<p/>" in place of the newline character,

However, that won't work either unless you turn off escaping on your outputText tag, since it will otherwise just print those tags on the screen.

It's really best not to attempt to do page formatting in backing beans. Doing so breaks the separation of concerns that defines MVC by putting View functionality (line formatting) into the Model (backing bean). A cleaner approach is to use a suitable JSF definition - for example a 1-column panelGrid or a dataTable.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: formatting a string from backbean
It's not a secret anymore!