4 Replies Latest reply on Sep 22, 2009 10:31 AM by israel.bgf

    Strange Behaviour: Datatable and Rerendering

    israel.bgf

      Hi, i found an strange behavior and wanted to know if it's a bug or maybe something that I do not understand pretty well about reRendering on iteration components.

      I have a table inside an column of another datatable, in that same column i have a button that triggers a reRender to a a4j:outputPanel, but when i click that button the value of the dataTable get evaluated again, even that i do not "rerendered" that region (ok that was very strange to understand). Here is the sample code (Seam 2.2.0, RichFaces 3.3.1)

      Bean.class
      -----

      @Name("bean")
      @Scope(ScopeType.PAGE)
      public class Bean {
      
       private List<String> list;
      
       @Create
       public void init(){
       list = new ArrayList<String>();
       list.add("1");
       }
      
       public double random(){
       return Math.random();
       }
      
       public List<String> generateList(){
       System.out.println("Darn! I shouldn't be invoked!");
       return new ArrayList<String>();
       }
      
       public List<String> getList() {
       return list;
       }
      
       public void setList(List<String> list) {
       this.list = list;
       }
      
      }
      


      test.xhtml
      ----------
      <?xml version="1.0" encoding="ISO-8859-1" ?>
      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:rich="http://richfaces.org/rich"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:s="http://jboss.com/products/seam/taglib">
      
      <body>
      
       <a4j:form>
       <rich:dataTable value="#{bean.list}">
       <rich:column>
       <f:facet name="header">
       Column
       </f:facet>
      
       <a4j:commandButton value="ReRender panelOne!" reRender="panelOne" ajaxSingle="true"/>
       <br/>
      
       <a4j:outputPanel id="panelOne">
       This is the panelOne: #{bean.random()}
       </a4j:outputPanel>
       <br/>
      
       <a4j:outputPanel id="cursedPanel">
       This is the panelTwo: #{bean.random()}
       <rich:dataTable value="#{bean.generateList()}">
       <rich:column>
       blabla...
       </rich:column>
       </rich:dataTable>
       </a4j:outputPanel>
      
       </rich:column>
       </rich:dataTable>
       </a4j:form>
      
      </body>
      
      </html>
      


      Clicking in the test button should rerender only the "panelOne", and it happens as the new random number appears. But the strange thing is that the generateList() method is called again (the sysout print its message) and even stranger is the fact that the random number of the panelTwo do not get "randomized" (as the panel is not a reRender target of the button).

      Is that normal?

      Thanks in advance,

      Israel

        • 1. Re: Strange Behaviour: Datatable and Rerendering
          nbelaevski

          Hi Israel,

          Please take a look: jira.jboss.org/jira/browse/RF-3341

          • 2. Re: Strange Behaviour: Datatable and Rerendering
            israel.bgf

            Thanks for the answer nbelaevski, it almost solve my problem but.. in my true requirement i need to do something like this (with the same bean code):

             <a4j:form>
             <rich:dataTable value="#{bean.list}">
             <rich:column>
             <f:facet name="header">
             Column
             </f:facet>
            
             <a4j:region renderRegionOnly="true">
             <a4j:outputPanel id="panelOne">
             This is the panelOne: #{bean.random()}
             </a4j:outputPanel>
             <br/>
            
             <a4j:commandButton value="ReRender panelOne!" reRender="panelOne" ajaxSingle="true"/>
             <br/>
             <a4j:commandButton value="ReRender cursedPanel!" reRender="cursedPanel" ajaxSingle="true"/>
             <br/>
             End of panel one...
             <br/>
             </a4j:region>
            
             <a4j:outputPanel id="cursedPanel">
             This is the panelTwo: #{bean.random()}
             <rich:dataTable value="#{bean.generateList()}">
             <rich:column>
             blabla...
             </rich:column>
             </rich:dataTable>
             </a4j:outputPanel>
            
             </rich:column>
             </rich:dataTable>
             </a4j:form>
            


            I have two buttons inside de a4j region, one of then just need to rerender internal stuff, ok no problem and the renderRegionOnly="true" works well. But i have another button and that one needs to reRender the outside table and it will not work with the renderRegionOnly.

            It's not easy to put the button outside the a4j:region cause it would break the layout of the components. Is there any other idea to solve this?

            (I though of putting an invisible button and making the internal button click the other button with javascript so the outside "invisible" button would do the work, but it looks odd and I wanted to know if there is any more elegant way of solving this)

            Thanks again,

            Israel

            • 3. Re: Strange Behaviour: Datatable and Rerendering
              nbelaevski

              Use "limitToList" then

              • 4. Re: Strange Behaviour: Datatable and Rerendering
                israel.bgf

                Thanks nbelaevski, that worked. That's the power of a single keyword. :)

                Thanks again,