Problem in comment out a JSF tag:
We can html comment
<!-- --> |
for commenting a JSF tag. But the problem here is that JSF still process the value expression and tag will appear in generated HTML.
JSF Comment:
<!-- <h:commandButton type="button" value="#{msg.buttonClickHerel}" /> --> |
JSF dataTable:
<!-- <h:commandButton type="button" value="Click Here" /> --> |
Solution of above problem:
We have two solutions of the above problem.
1. Use facelets.SKIP_COMMENTS in web.xml file and set it to true.
<context-param> <param-name>facelets.SKIP_COMMENTS</param-name> <param-value>true</param-value> </context-param> |
2. Use ui:remove tag:
JSF ui:remove tag is used to define the content we want to remove.
Example:
test.xhtml
<?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" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:body> <h2>JSF ui remove example.</h2> <ui:remove> <h:outputText value="Hello World" /> </ui:remove> </h:body> </html> |
faces-config.xml
<?xml version="1.0" encoding="windows-1252"?> <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"> </faces-config> |
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <servlet> <servlet-name>faces</servlet-name> <servlet-class> javax.faces.webapp.FacesServlet <servlet-mapping> <servlet-name>faces</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> </web-app> |
URL:
http://localhost:7001/JSFExample48/faces/test.xhtml