1

I have a code block like this in JSF

<div class="textile">
    <h:outputText escape="false"
        value="#{NotificationContentWFHelper.generateContent(notification)}"/>
</div>

The string generated in value tag comes from database stored as CLOB which was created in Java.

I want a particular part in this string to be shown as table in the output like below.

Item 1081 has become the new reference item.

1081              1200              12000             0                 10                1081              
1073              1000              10000             0                 10                1073              
1069              800               8000              0                 10                1069              
1079              0                 0                 0                 0                 1079              
1074              0                 0                 0                 0                 1074              

Each row in table is created using format

String.format("%-18s%-18s%-18s%-18s%-18s%-18s", rowValues);

As the output in our application doesn't use monospace fonts, I couldn't show it as table. So I tried using the <code> tag only for the tabular part. The tag was parsed but it skipped all the spaces showing

Item 1081 has become the new reference item.

1081 1200 12000 0 10 1081
1073 1000 10000 0 10 1073
1069 800 8000 0 10 1069
1079 0 0 0 0 1079
1074 0 0 0 0 1074

I further tried builder.toString().replace(' ', NON_BREAKING_SPACE); where final char NON_BREAKING_SPACE = ' '; but got this

Item 1081 has become the new reference item.

1081&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;1200&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;12000&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;1081&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
1073&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;1000&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10000&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;1073&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
1069&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;800&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;8000&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;10&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;1069&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
1079&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;1079&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
1074&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;1074&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;

Using any other tag apart from <code> doesn't parse like HTML. I tried using <samp>, <p>, <table> (with <tr> & <td>). It comes up as

Item 1081 has become the new reference item.

<samp>1081              1200              12000             0                 10                1081              
1073              1000              10000             0                 10                1073              
1069              800               8000              0                 10                1069              
1079              0                 0                 0                 0                 1079              
1074              0                 0                 0                 0                 1074              
</samp>

What am I missing here?

Note: I cannot change the XHTML code as this a very specific case where I need table. I do not want to disturb other things or put extra overhead on other 99 stuff for this 1 in 100. Any other approach by modifying java code could be suitable if it renders the desired output.

Update: As per Component to inject and interpret String with HTML code into JSF page html should be parsed as escape is false, but it does not work in my case.

Mukund Jalan
  • 1,145
  • 20
  • 39

0 Answers0