July 29 2015

Jsf rendered attribute example

Jsf rendered attribute example

The rendered attribute which uses Boolean EL expression indicates whether a component is currently visible or not. The property is useful when you want to hide components for specific users or based on condition. The default value of rendered attribute is true.


<h:outputText value=”mapping” rendered=”Boolean EL expression” />

rendered Display the component
true Yes
false No


In the below example, rendered attribute takes boolean value or boolean expression and displays the component accordingly. Approve-1 and Approve-3 button’s rendered attribute resolves to true whereas Approve-2 button’s rendered attribute resolves to false.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml"

<title>Jsf rendered attribute example</title>


<h2>Jsf rendered attribute example</h2>

<h:messages />
<h:panelGrid columns="2">

<h:outputText value="Name" />

<h:outputText value="#{leaveManagedBean.fullName}" />
<h:commandButton value="Approve-1" rendered="true"
action="#{leaveManagedBean.approveLeave}" />

<h:commandButton value="Approve-2"
action="#{leaveManagedBean.approveLeave}" />

<h:commandButton value="Approve-3"
action="#{leaveManagedBean.approveLeave}" />



package com.answersz;

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

@ManagedBean(name = "leaveManagedBean")
public class LeaveManagedBean {

public String fullName = "Michelle";

public String loggedInUserRole = "MANAGER";

public Boolean displayApprove = false;

public String approveLeave() {
// code goes here
return null;

public String getFullName() {
return fullName;

public void setFullName(String fullName) {
this.fullName = fullName;

public String getLoggedInUserRole() {
return loggedInUserRole;

public void setLoggedInUserRole(String loggedInUserRole) {
this.loggedInUserRole = loggedInUserRole;

public Boolean getDisplayApprove() {
return displayApprove;

public void setDisplayApprove(Boolean displayApprove) {
this.displayApprove = displayApprove;


jsfrendered attribute

Copyright © 2014. All rights reserved.

Posted July 29, 2015 by answersz in category Jsf

Leave a Comment

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