4 Replies Latest reply on Sep 30, 2013 12:17 PM by Immo Benjes

    Bug with persisting table sorting when using dataScroller

    Immo Benjes Newbie

      Hi,

      I think I've found a bug in RichFaces 4.3.3.

       

      If you persist the table state of a rich:extendedDataTable the sorting order is not restored when you reload the page if the extendedDataTable has a rich:dataScroller.

      However when you use the dataScroller to go to the 2nd page and then back to the 1st page the sorting is correct again.

       

      This causes a second problem (which I haven't managed to isolate yet) that actions in the table (e.g. calling an action method and passing in the column var) does not work. Please note this does work in the example code below, but not in our real live table. If I go to the 2nd page all links in that table work.

       

      Screen Shot 2013-09-18 at 10.57.53.png

      The screenshot above shows the sorting is done for the column name (ascending).

      Now after reloading the page:

      Screen Shot 2013-09-18 at 10.58.13.png

      The ordering is back to the ordering on the backing bean, note however that the table state still specifies name: ascending as the sort order.

      If you remove the rich:dataScroller it works fine.

       

      If you call #{rich:component('testtable')}.sort() nothing happens (is this method still correct?) clearSorting() does work however.

       

       

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
      <ui:composition 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:a="http://richfaces.org/a4j"
                      xmlns:s="http://jboss.org/schema/seam/taglib"
                      xmlns:rich="http://richfaces.org/rich">
          <f:view>
              <h:head>
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
              </h:head>
              <h:body>
                  <h:form id="tform">
      
                      <a:outputPanel ajaxRendered="true">
                          <h:outputText id="STATE" value="TABLE: #{tableState.state}"/>
                      </a:outputPanel>
      
                      <h:outputText id="info" value="#{tableTest.entity}"/>
      
                      <a onclick="console.log('Sorting');#{rich:component('testtable')}.sort()"> Sort </a>
                      <a onclick="console.log('Sorting');#{rich:component('testtable')}.clearSorting()"> Clear </a>
      
                      <rich:extendedDataTable id="testtable" value="#{tableTest.list}" rows="3"
                                              var="entity" tableState="#{tableState.state}">
                          <rich:column sortBy="#{entity.id}">
                              <f:facet id="eid" name="header">ID</f:facet>
                              #{entity.id}
                          </rich:column>
                          <rich:column id="name" sortBy="#{entity.name}">
                              <f:facet name="header">Name</f:facet>
                              #{entity.name}
                          </rich:column>
                          <rich:column id="action">
                              <f:facet name="header">action</f:facet>
                              <a:commandLink action="#{tableTest.setEntity(entity)}"
                                             render="info" execute="@this" value="Set"/>
                          </rich:column>
                          <f:facet name="footer">
                              <rich:dataScroller/>
                          </f:facet>
      
                      </rich:extendedDataTable>
      
                  </h:form>
              </h:body>
          </f:view>
      </ui:composition>
      

       

      The backing bean:

      package test.richfaces;
      
      import java.util.Arrays;
      import java.util.List;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.log.Log;
      
      
      @Name("tableTest")
      @Scope(ScopeType.CONVERSATION)
      public class TableTest {
      
        private TestEntity entity;
      
        @Logger Log log;
      
        private List<TestEntity> list = Arrays.asList(new TestEntity(3,"BMW"),new TestEntity(1,"Audi"),new TestEntity(9,"Bentley"),new TestEntity(5,"Porsche"));
      
        public List<TestEntity> getList() {
            return list;
        }
      
        public void setList(List<TestEntity> list) {
            this.list = list;
        }
      
        public TestEntity getEntity() {
            return entity;
        }
      
        public void setEntity(TestEntity entity) {
            log.info("Setting entity  #0",entity); 
            this.entity = entity;
        }
      
      
      }
      
      

       

      and a session scoped bean to store the table state:

      package test.richfaces;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      @Name("tableState")
      @Scope(ScopeType.SESSION)
      public class TableState {
      
        private String state;
      
        public String getState() {
            return state;
        }
      
        public void setState(String state) {
            this.state = state;
        }
      
      }
      
      

       

      and the 'entity' for the table

      package test.richfaces;
      
      public class TestEntity {
      
       private int id;
      
        public int getId() {
            return id;
        }
      
        public void setId(int id) {
            this.id = id;
        }
      
        public String getName() {
            return name;
        }
      
        public void setName(String name) {
            this.name = name;
        }
      
        private String name;
      
        public TestEntity(int id, String name){
            this.id = id;
        this.name = name;
        }
      
       @Override
        public String toString() {
            return "TestEntity [id=" + id + ", name=" + name + "]";
        }
      
      }