hi
How do I properly render a multi-line text value using HTML div-tags in a JSF application, preferably using ADF Faces components?
The multi-line text value could be in a database table column or returned from a database PL/SQL function, but to simplify things, it is available from a backing bean like this:
public class NewLinePage
{
public static final String LINE_SEPARATOR =
System.getProperty("line.separator");
public static final String MULTI_LINE_TEXT = "a first line"
+ LINE_SEPARATOR + "a special char é ç € ñ line"
+ LINE_SEPARATOR + "a third line";
public String getMultiLineText()
{
return MULTI_LINE_TEXT;
}
}
Notice that it also has some special characters on the second line.
see also http://verveja.footsteps.be/~verveja/files/oracle/NewLineStuffApp-v0.01.zip (check README.txt)
If I use an af:outputText component like this ...
<af:outputText id="oTextId"
value="#{backing_newLinePage.multiLineText}"/>
... it renders like this (note that I had to add a space after the "&" in HTML code, to have those escaped characters show up somewhat recognizable in this forum post) ...
<span id="myFormId:oTextId">a first line
a special char & eacute; & ccedil; & #8364; & ntilde; line
a third line</span>
... but I would like it to be rendered like this ...
<div>a first line</div><div>a special char & eacute; & ccedil; & #8364; & ntilde; line</div><div>a third line</div>
So I tried to work with a
javax.faces.convert.Converter to solve this.
(1) If I use an af:outputText component with "newLineToDivConverter" like this ...
<af:outputText id="oTextToDivId"
value="#{backing_newLinePage.multiLineText}"
converter="#{newLineToDivConverter}"/>
... it renders like this ...
<span id="myFormId:oTextToDivId">& lt;div& gt;a first line& lt;/div& gt;& lt;div& gt;a special char & eacute; & ccedil; & #8364; & ntilde; line& lt;/div& gt;& lt;div& gt;a third line& lt;/div& gt;</span>
... so, now the div-tags are also escaped (and visible on the page)
(2) If I use an af:outputText component with "newLineToDivConverter" and escape false like this ...
<af:outputText id="oTextToDivNoEscapeId"
value="#{backing_newLinePage.multiLineText}"
converter="#{newLineToDivConverter}"
escape="false"/>
... it renders like this ...
<div>a first line</div><div>a special char é ç € ñ line</div><div>a third line</div>
... so, now the special characters are not escaped
(3) If I use an af:outputFormatted component like this ...
<af:outputFormatted id="oFormattedId"
value="#{backing_newLinePage.multiLineText}"/>
... it renders like this ...
<span id="myFormId:oFormattedId">a first line
a special char & eacute; & ccedil; & #8364; & ntilde; line
a third line</span>
... so, this shows up on one line in the page
(4) If I use an af:outputFormatted component with "newLineToDivConverter" like this ...
<af:outputFormatted id="oFormattedToDivId"
value="#{backing_newLinePage.multiLineText}"
converter="#{newLineToDivConverter}"/>
... it renders like this ...
<span id="myFormId:oFormattedToDivId">a first linea special char & eacute; & ccedil; & #8364; & ntilde; linea third line</span>
... so, here the div-tags are stripped (the
af:outputFormatted component documentation doesn't mention the div-tag as supported, but the br-tag is supported)
(5) If I use an af:outputFormatted component with a different "newLineToBrConverter" like this ...
<af:outputFormatted id="oFormattedToBrId"
value="#{backing_newLinePage.multiLineText}"
converter="#{newLineToBrConverter}"/>
... it renders like this ...
<span id="myFormId:oFormattedToBrId">a first line<br>a special char & eacute; & ccedil; & #8364; & ntilde; line<br>a third line</span>
... so, this is functionally similar when shown on the page, but it is not using div-tags
questions:
(q1) What would be the preferred approach to get this rendered with div-tags like this:
<div>a first line</div><div>a special char & eacute; & ccedil; & #8364; & ntilde; line</div><div>a third line</div>
(q2) It looks like using a
Converter for this purpose is heavily dependant on the UI component used, I wonder if there are other "JSF extension points" I should be looking for to solve this.
(using JDeveloper 10.1.3.3.0)
many thanks
Jan Vervecken