1 Reply Latest reply on Mar 20, 2009 2:49 PM by Sergey Smirnov

    using Rendered and Rerender together

    E Aish Novice

      Hi,

      I read that Rerendering an component which has a conditional rendering even though works is not good practice.

      For eg: In the below sample code, the below link is to show the "first" link and to display the first set of records from the database. If the display already has the first set of records, then this link should not be displayed. So, for every page of the database records that is navigated, we need to check if this link should be enabled or not.

      Please let me know if this is ok (it works fine for now). If not, please let me know what is the other way of doing it

      Thanks
      Aish

      <a4j:outputPanel id="aa">
      <a4j:commandLink value="first &lt;&lt; " id="cButton2" action="#{process.first}" rendered="#{process.chkRecords}" reRender="oPanel, oPanel1"/>

      </a4j:outputPanel>

        • 1. Re: using Rendered and Rerender together
          Sergey Smirnov Master

          Aish, it is not about a good or a bad practice, but about the specific of the JSF framework and its hidden limitations.

          Actually, it seems for me that you mismatched two different aspects
          1. golder rule that say do not point with re-rendered to the component that has rendered attribute
          2. rules about using rendered attribute for the jsf command component (ajax or standard one - it does not mater)

          <a4j:commandLink value="first << " id="cButton2"
           action="#{process.first}" rendered="#{process.chkRecords}" />



          This is a known JSF trap. To make the link visible, it is enough to have #{process.chkRecords} evaluated to true at the beginning of the 6th JSF lifecycle phase. However, to have the command component workable (i.e. when action listener and action method are invoked), you have to have the #{process.chkRecords} evaluated to true at the beginning of the 2nd next JSF lifecycle phase.

          I.e. you might have a situation when the link is visible, but unworkable.
          Actually, this problem has nothing to to with RichFaces. It comes from the core JSF.
          BTW, you will face tht same problem even 'rendered located outside. Like:

          <h:panelGrid rendered="#{foo.bar}">
           ....
           <h:commandLink />
           ...
          </h:panelGrid>


          If #{foo} is a request scope bean and #{foo.bar} is initiated with false, the link will not work even you set #{foo.bar} to true in your action method (on the 5th phase) in order to have it visible.