simpleTogglePanel - when rendered attribute is an EL express
truyen Jan 20, 2009 4:51 PMI have a rich simpleTogglePanel whose "rendered" attribute is bound to a backing bean field that evaluates to a small boolean. What i want to achieve is when the rendered attribute is true the simpleTogglePanel would be shown, and hidden if false. The problem is even when the backing bean rendered value is true the simpleTogglePanel won't show. What am I doing wrong? Below is the markup and backing bean code. It would only work if i hard-coded the backing bean's rendered value to "true".
Thanks for your help.
<!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" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Testing RichFaces:SimpleTogglePanel</title> </head> <body> <rich:messages layout="table" globalOnly="true" style="color:red;"/> panelBean.rendered==#{panelBean.rendered}<br/> panelBean.showPanel==#{panelBean.showPanel} <h:form id="form1"> <rich:simpleTogglePanel opened="true" id="errorPanel" rendered="#{panelBean.showPanel}" switchType="client" label=""> <f:facet name="header"> <span class="error">1) rendered is an EL expression, opened=true</span> </f:facet> Expand/Collapse doesn't work </rich:simpleTogglePanel> <rich:simpleTogglePanel opened="false" id="errorPanel4" rendered="#{!empty facesContext.maximumSeverity}" switchType="client" label=""> <f:facet name="header"> <span class="error">2) rendered is an EL expression, opened=false</span> </f:facet> Expand/Collapse doesn't work </rich:simpleTogglePanel> <h:outputLabel id="userNameLabel" for="usernameInput" value="User Name:" /> <h:inputText id="usernameInput" value="#{panelBean.userId}" tabindex="1" /> <br /> <h:outputLabel id="passwordLabel" for="passwordInput" value="Password:" /> <h:inputSecret id="passwordInput" value="#{panelBean.password}" tabindex="2" /> <br /> <a4j:commandButton id="loginButton" value="Sign In" action="#{panelBean.login}" tabindex="3" /> <br /> </h:form> </body> </html>
Backing bean ==================
import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import org.jboss.seam.annotations.Name; @Name("panelBean") public class PanelBean { private boolean rendered = false; private String userId; private String password; private boolean showPanel = false; public String login(){ System.out.println("userId==" + userId); System.out.println("password==" + password); if(userId != null && password!= null && userId.length()>0) { rendered=false; showPanel = false; } else { rendered=true; showPanel = true; FacesContext facesContext = FacesContext.getCurrentInstance(); FacesMessage message = new FacesMessage (FacesMessage.SEVERITY_ERROR, "1 Error Found: User Name or Password is incorrect", "1 Error Found: User Name or Password is incorrect"); facesContext.addMessage(null, message); } return "aaaa"; } public boolean getShowPanel() { System.out.println("getShowPanel==" + showPanel); return showPanel; // DOESN'T WORK // return true; // THIS WORKS } public boolean getRendered() { System.out.println("getRendered==" + rendered); return rendered; // DOESN'T WORK // return true; // THIS WORKS } public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }