JSF h:outputText with body and value attribute 

Joined:
08/13/2009
Posts:
164

December 03, 2011 12:31:20    Last update: December 03, 2011 12:33:23
The <h:outputText> tag generates different output for body text and value attribute. I tested the following with Apache MyFaces 2.1.3:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
    <title>outputText test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </h:head>

    <h:body>
    <div id="header"><h2>Test h:outputText</h2></div>
    <div id="content">
	<h:outputText escape="false" value="&lt;table border='1' cellspacing='0' cellpadding='4'&gt;"/>
	    <tr><td>Table cell</td></tr>
	<h:outputText escape="false" value="&lt;/table&gt;"/>

	<h:outputText escape="false">
	    &lt;table border='1' cellspacing='0' cellpadding='4'&gt;
	</h:outputText>
	    <tr><td>Table cell</td></tr>
	<h:outputText escape="false">
	    &lt;/table&gt;
	</h:outputText>
    </div>
   </h:body>
</html>


With value attribute, the output was:
<table border='1' cellspacing='0' cellpadding='4'>
	    <tr><td>Table cell</td></tr></table>


With text in body, the output was (i.e., the text was escaped despite escape="false"):
&lt;table border='1' cellspacing='0' cellpadding='4'&gt;
	    <tr><td>Table cell</td></tr>
	    &lt;/table&gt;
Share |
| Comment  | Tags