1
votes

I need to output the html text, which is stored in database. The text is generated by the rich editor, so contains bad-formed html (non-closed tags like <br>). So I have the problem how to print it on the page.

If I use:

#{document.content}

It prints the escaped html document, and all tags are displayed on the page (the code itself contains "& lt;" instead of <)

The visible solution - to use h:outputText with escape="false:

<h:outputText value="#{document.content}" escape="false" /> 

But it prints the html only until it is well-xml-formed: the text is stopped on the first <br> tag. Seems, JSF parses the content of the document.content and stops when cannot do it. I don't really need JSF to parse the content, simply output!

The following code didn't help either:

<h:outputText value="lt![CDATA[#{document.content}]]gt" escape="false" />
1

1 Answers

2
votes

Ok, that seemed to be Chrome error. After I changed DOCTYPE to html transitive it showed "Entity ‘nbsp’ not defined" error and didn't render the content. But in other browsers everything rendered ok! Even after I rollbacked the DOCTYPE to xhtml strict - Firefox and Opera displayed the content perfectly and didn't pay much attention to bad-formed html!

Didn't dive deep, but this is somehow linked with Webkit - the engine for Chrome.

Update: use < f:view contentType="text/html" > so that this worked ok in Chrome and Safari.

Hope this will help anyone else