Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

formatting a string from backbean

 
Dura Hurtado
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 18419
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Evil is afoot. But this tiny ad is just an ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!