3 Replies Latest reply on Feb 16, 2009 9:43 AM by Nick Belaevski

    simpleTogglePanel - when rendered attribute is an EL express

    truyen vu Newbie

      I 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;
       }
      
      }
      




        • 1. Re: simpleTogglePanel - when rendered attribute is an EL exp
          Nick Belaevski Master

          Hi,

          You should update panel by AJAX action. Read more about a4j:outputPanel in documentation.

          • 2. Re: simpleTogglePanel - when rendered attribute is an EL exp
            Hugo Wurzelbutz Newbie

            hi

            i have a similar question:

            i'm trying to render a simpleTogglePannel based on a id set or not set.

            <a4j:outputPanel id="linkswitchTop" rendered="#{bean.id gt 0}">
             <rich:simpleTogglePanel label="Links" switchType="ajax" id="linkswitch" opened="false" >
             <a4j:commandButton onclick="#{rich:component('mp')}.show()" value="Neu" reRender="modal1" action="#">
             </a4j:commandButton>
             <rich:dataList var="d" value="#{linkRessources}">
             <a4j:outputPanel>
             <h:outputText value="Name: #{d.name}" /><br/>
             <h:outputText value="Link: #{d.object}" /> <br/>
             <h:outputText value="Reihenfolge: #{d.sortOrder}" />
             <a4j:support event="onclick" onclick="#{rich:component('mp')}.show()" action="#" reRender="modal1">
             </a4j:support>
             </a4j:outputPanel>
             </rich:dataList>
             </rich:simpleTogglePanel>
             </a4j:outputPanel>


            the rendering works but the simpleTogglePannel wont open after clicking on it. it works well as soon as i remove the rendered attribute.

            • 3. Re: simpleTogglePanel - when rendered attribute is an EL exp
              Nick Belaevski Master

               

              "wurzelbutz" wrote:
              hi

              i have a similar question:

              i'm trying to render a simpleTogglePannel based on a id set or not set.

              <a4j:outputPanel id="linkswitchTop" rendered="#{bean.id gt 0}">
               <rich:simpleTogglePanel label="Links" switchType="ajax" id="linkswitch" opened="false" >
               <a4j:commandButton onclick="#{rich:component('mp')}.show()" value="Neu" reRender="modal1" action="#">
               </a4j:commandButton>
               <rich:dataList var="d" value="#{linkRessources}">
               <a4j:outputPanel>
               <h:outputText value="Name: #{d.name}" /><br/>
               <h:outputText value="Link: #{d.object}" /> <br/>
               <h:outputText value="Reihenfolge: #{d.sortOrder}" />
               <a4j:support event="onclick" onclick="#{rich:component('mp')}.show()" action="#" reRender="modal1">
               </a4j:support>
               </a4j:outputPanel>
               </rich:dataList>
               </rich:simpleTogglePanel>
               </a4j:outputPanel>


              the rendering works but the simpleTogglePannel wont open after clicking on it. it works well as soon as i remove the rendered attribute.

              Most probably it has rendered="false" for subsequent requests. Is "bean" session-scoped?