JavaBeat
Search JavaBeat

JSF Links
JSF Home
JSF Tips
JSF News
JavaBeat
Home
Articles
Tips
Code
QnA
Forums

How to use rendered attribute in JSF?


Rendered attribute in JSF is used for displaying the components based on the condition. This attribute is applicable for most of the components in the JSF tag library. The following is the simple example demonstrates the use of rendered attribute.

JSP File


<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<html>
    <body>
        <f:view>
            <h:form>
                <h:outputText value="One is Set" rendered="#{jsfBean.employeeName=='One'}"/>
                <h:outputText value="One is Not Set" rendered="#{jsfBean.employeeName!='One'}"/>
                <h:commandButton value="Submit" action="#{jsfBean.submit}"/>
            </h:form>
        </f:view>
    </body>  
</html>

JAVA File


package javabeat.net.jsf.core;

/*
 * author : http://www.javabeat.net
 */
public class JsfTrainingBean {
    private String employeeName;
   
    public String getEmployeeName() {
        return employeeName;
    }
   
    public void setEmployeeName(String employeeName) {
        this.employeeName = employeeName;
    }
   
    public String submit(){
        this.employeeName = "One";
        return "success";
    }
   
}

faces-config.xml


<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>

    <!-- Tree View System Topology Bean -->
    <managed-bean>
        <managed-bean-name>jsfBean</managed-bean-name>
        <managed-bean-class>
            javabeat.net.jsf.core.JsfTrainingBean
        </managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
</faces-config>

Read the full article here

Sponsors
Webmaster Hosting Forum
Java Jobs
MyVideoLib
India News
Internet Advances
Latest QnA
SCJD Tips
When we start a thread by applying start() method on it ,how does it knows that to execute run()method?
About Wrapper class in Java
How to configure weblogic 7.0 in MyEclipse?
Static Block and Static Initializer in Java

JavaBeat Media (2004-2008), India
javabeat | planetoss | links directory | advertise
Copyright (2004 - 2008), JavaBeat