*
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
JavaRanch » Java Forums » Java » JSF
Bookmark "formatting a string from backbean" Watch "formatting a string from backbean" New topic
Author

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?

bbbbbbbbb

bbbbbbbbb

bbbbbbbbb


Thanks


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
Consider Paul's rocket mass heater.
 
subject: formatting a string from backbean
 
Similar Threads
Integer.parseInt(String)
Text Area Problem... Pls Help
Can static methods be inherited?
Converting a String to uppercase?
Read the Windows Registry from java