JSF 2 UI Remove Example

Sometimes, to find out which part of a jsf view causes a stack trace, you may want to use the time-honored divide-and-conquer strategy of commenting out parts of the page to isolate the offending component.

Somewhat surprisingly, the XML comments <!– … –> are not useful for this purpose for example when you comment out a button in an XHTML page, JSF will process the value expression, and place the result, as a comment, in the generated HTML page. In case the expression throws an exception, then the XML comments don’t help you at all. Since JSF 2.0 a new Tag has provided for commenting the undesired components. Instead of using comments JSF provides you a new Tag ui:remove.

Also Read:

1.Managed Bean


package net.javabeat.jsf.data;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

public class IndexBean {
	private String evaluatedProperty = "Please Use ui:remove rather using of XML comments";
	private String evaluatedMessage = "Am I Evaluated";

	public String getEvaluatedProperty() {
		System.out.println("Even you're commenting out my associated output component, "
				+ "however it executes the getEvaluatedProperty."
				+ "Using ui:remove will cause this expression to be not executed");
		return evaluatedProperty;

	public void setEvaluatedProperty(String evaluatedProperty) {
		this.evaluatedProperty = evaluatedProperty;

	public String getEvaluatedMessage() {
		return evaluatedMessage;

	public void setEvaluatedMessage(String evaluatedMessage) {
		this.evaluatedMessage = evaluatedMessage;

2. The View


<html xmlns="http://www.w3.org/1999/xhtml"
	<h:outputScript library="javax.faces" name="jsf.js"/>
		<h1>JavaBeat JSF 2.2 Examples</h1>
		<h2>JSF2 UI Remove Example</h2>
		<h:form prependId="false">
				<h:outputText value="#{indexBean.evaluatedMessage}"></h:outputText>
				<h:output value="#{indexBean.evaluatedProperty}"/>

3. The Deployment Descriptor


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5" metadata-complete="true">
		<description>State saving method: 'client' or 'server'
						(=default). See JSF Specification 2.5.2
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-name>Faces Servlet</servlet-name>

4. Faces Configuration File

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"

5. JSF 2 UI Remove Demo

The below snapshot shows you the impact of using ui:remove Tag for preventing execution and rendition of undesired jsf components.

JSF 2 UI Remove Example

  • As you’ve noted the two output components aren’t rendered, cause the first one has been using the ui:remove and the second one has been using the XML comments.
  • But if you’ve looked at the JVM console, you are almost getting a message from that commenting component using the XML comments.
  • The point that you have to get it, is that the ui:remove preventing the evaluation of the JSF expressions and the rendition. Meanwhile the XML comments has evaluated the jsf expression without rendering the component.

6. Console Messages

The message that you will get once you are executing the sample program is as follow

Even you're commenting out my associated output component, however it executes the getEvaluatedProperty.Using ui:remove will cause this expression to be not executed

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>