JSF Comments

Commenting in jsf pages:

It can be done in two ways:

1) With Configuration in file

2) With ui:remove tag

Suppose we have a user.xhtml page:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"   
      xmlns:h="http://java.sun.com/jsf/html"
      >
     <h:body>
 
     <!-- 
    	<h:commandButton type="button" 
    		value="#{msg.buttonLabel}" />
      -->
 
    </h:body>
</html>

Here we have commented out the button using html comments.

Suppose buttonLabel has value: Hit Me in your bundle(property file)

Output generated html will be as:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
   <body> 
     <!-- 
    	<h:commandButton type="button" 
    		value="Hit Me" />
      -->
   </body> 
</html>

To avoid this thing we can do setting in web.xml file as:

<context-param>
    <param-name>facelets.SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
</context-param>

Now the output html file will be as:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
	<body> 
 
	</body> 
</html>