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
|