4 Replies Latest reply on Apr 11, 2012 10:17 AM by songjinglim

    richface rendered

    songjinglim Newbie

      I'm using richface 4.2.1.CR, don't know is the problem with richface or jsf, I face a very unexplained problem where when EL (expression language) for component rendered attribute return true, the El will exec 5 time!

       

      [test.xhtml]

       

      <!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:rich="http://richfaces.org/rich"

          xmlns:a4j="http://richfaces.org/a4j">

       

      <h:outputText rendered="#{userProfileBean.testBoolean}"></h:outputText>

      </html>

       

      [UserProfileBean.java]

       

      @ManagedBean(name = "userProfileBean")

      @SessionScoped

      @SuppressWarnings("serial")

      public class UserProfileBean implements Cloneable, Serializable{

          private boolean testBoolean = true;

       

          public boolean isTestBoolean() {

              String methodName = "isAutoGeneratePwd";

       

              logger.logp(Level.SEVERE, className, methodName, ">>>testBoolean=" +testBoolean);          

              return testBoolean;

          }

       

       

          public void setTestBoolean(boolean testBoolean) {

              this.testBoolean = testBoolean;

          }

      }

       

      Output from log:

       

      10/04/2012 3:04:39 PM com.cea.apps.common.faces.bean.UserProfileBean isAutoGeneratePwd SEVERE: >>>testBoolean=true

      10/04/2012 3:04:39 PM com.cea.apps.common.faces.bean.UserProfileBean isAutoGeneratePwd SEVERE: >>>testBoolean=true

      10/04/2012 3:04:39 PM com.cea.apps.common.faces.bean.UserProfileBean isAutoGeneratePwd SEVERE: >>>testBoolean=true

      10/04/2012 3:04:39 PM com.cea.apps.common.faces.bean.UserProfileBean isAutoGeneratePwd SEVERE: >>>testBoolean=true

      10/04/2012 3:04:39 PM com.cea.apps.common.faces.bean.UserProfileBean isAutoGeneratePwd SEVERE: >>>testBoolean=true

       

      And if I change the condition to false:

       

      <h:outputText rendered="#{not userProfileBean.testBoolean}"></h:outputText>

       

      EL only exec once where is correct, here the log:

       

      10/04/2012 3:05:21 PM com.cea.apps.common.faces.bean.UserProfileBean isAutoGeneratePwd SEVERE: >>>testBoolean=true

       

      Any help on this?

       

      p/s: The component I mention include <rich:panel> <h:panelGrid>

        • 1. Re: richface rendered
          Alex Perstinski Newbie

          For HtmlOutputText following sequence happens:

           

          encodeAll() -> first check to see if component should be renderd
          encodeBegin() -> second check
          encodeChildren() -> third check
          encodeEnd() -> fourth check
          inside encodeEnd() TextRenderer.encodeEnd() is called resulting fifth check.

           

          And nobody guarantees that rendered attribute will be evaluated only once.
          And of course if rendered attribute returns false in first check, than no additional checks will be performed

          1 of 1 people found this helpful
          • 2. Re: richface rendered
            songjinglim Newbie

            Hi Alex

             

            Thanks for the reply.  That explain the senario.

             

            However if the expression result is false or with 'not' operator, jsf component only evaluate the expression once.  Should the same logic flow apply to true result right?

             

            e.g: testBoolean return true, and with 'not' operator the whole el result is false and this el condition only evaluate one (only one statement of log).

            <h:outputText rendered="#{not userProfileBean.testBoolean}"></h:outputText>

            • 3. Re: richface rendered
              Alex Perstinski Newbie

              See, if rendered is false in first check, than encodeBegin(), encodeChildren(), etc is not called...That's why it is evaulated only once, however in case of true there are more than one separated function call...And the rendered should be evaluated in each of them in case if someone changes the sequence or the attribute changed between calls.

              • 4. Re: richface rendered
                songjinglim Newbie

                Thanks Alex,

                 

                That make sense.