Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

formatting a string from backbean  RSS feed

 
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: 18709
71
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.

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!