tags:

views:

271

answers:

1

Hey,

I have a method that gives back a formatted XML string. I want to show that on a JSF page in a nicely wrapped, readable way. I used this solution first.

<pre><h:outputText value="myBean.xml"/></pre>

The result is indented, but it doesn't wrap very long lines (with a lot of attributes for e.g.)

RichFaces is also available in my project. What would you suggest?

Thanks in advance, Daniel

+3  A: 

Not sure if I understand you right, but if it is a plain vanilla String with XML data which you want to display as-is in the JSF page, then the first logical step would be to escape the HTML entities so that it's not been parsed as HTML. You can use h:outputText for this, it by default escapes HTML entities (which is controllable by the 'escape' attribute by the way):

<h:outputText value="#{bean.xmlString}" />

Or if it is formatted and you want to preserve the formatting, then apply the CSS white-space:pre property on the parent HTML element.

Or if you want to add syntax highlighting (colors and so on), then consider a Javascript library which does the task. Googling "javascript xml syntax highlighting" should yield enough results.

BalusC
Thanks! I will give the credit to you. However I was looking for white-space: pre-wrap :)
wheelie
Take care: pre-wrap doesn't work in IE up to with 7, nor in FF2.Also see http://www.quirksmode.org/css/whitespace.html
BalusC
Thanks, that was exactly what I was looking for!
Markos Fragkakis
@Markos: you're welcome. Interesting detail: this one was my first answer ever on Stackoverflow! :D
BalusC