3 Replies Latest reply on Apr 25, 2013 3:30 AM by dako ak

    RF 4.3.1, ExtendedDataTable: columnsOrder doesnt work after changing order

    dako ak Newbie

      Hi all,

       

      according to the resolved bug RF-11776 I tried the attribute columnsOrder in ExtendedDataTable.

      I have a simple test case with a data table and an action button. Within the action button method I change the String Array of the attribute columnsOrder but the columns of the data table is rendered in the old order.

       

      I have appended a test project to reproduce it.

      I have created a JIRA bug: https://issues.jboss.org/browse/RF-12928

       

      Maybe someone knows a workaround.

      The project is tested in Tomcat 7 with Mojarra 2.1.21.

      the same results in JBoss 6 and Mojarra 2.1.17.

       

      And now the code:

       

      xhtml page:

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <!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:ui="http://java.sun.com/jsf/facelets"
              xmlns:f="http://java.sun.com/jsf/core"
              xmlns:h="http://java.sun.com/jsf/html"
              xmlns:a4j="http://richfaces.org/a4j"
              xmlns:rich="http://richfaces.org/rich">
      
      <h:head>
          <title>RichFaces-Test: start page</title>
      </h:head>
      <h:body>
          <h3>RichFaces-Test: start page</h3>
          <h:form id="overviewForm">
              <p>
                  <h:outputText value="List of persons:" /> 
              </p>
      
              <p>
                  <a4j:commandButton value="Change columns order(Ajax)" action="#{overviewController.changeColumnsOrderWithAjax()}" render="overviewTable" immediate="true"/>
              </p>
              <p>
                  <h:commandButton value="Change columns order(full refresh)" action="#{overviewController.changeColumnsOrderFullRefresh()}" immediate="true"/>
              </p>
      
      
              <rich:extendedDataTable id="overviewTable" rowKeyVar="index"
                  columnsOrder="#{overviewController.columnsOrder}"
                  value="#{overviewController.tableItems}" var="tableItem"
                  rows="15">
      
                  <f:facet name="header">
                  </f:facet>
      
                  <rich:column id="city">
                      <f:facet name="header">
                          <h:outputText value="City" />    
                      </f:facet>
                      <h:outputText value="#{tableItem.city}" />                
                  </rich:column>
      
                  <rich:column id="firstName">
                      <f:facet name="header">
                          <h:outputText value="First Name" />    
                      </f:facet>
                      <h:outputText value="#{tableItem.firstName}" />                
                  </rich:column>
      
                  <rich:column id="country">
                      <f:facet name="header">
                          <h:outputText value="Country" />    
                      </f:facet>
                      <h:outputText value="#{tableItem.country}" />                
                  </rich:column>
      
              </rich:extendedDataTable>    
      
          </h:form>
      </h:body>
      </html>
      

       

       

      ManagedBean:

      package org.richfaces.test.ak;
      
      import java.io.Serializable;
      import java.util.ArrayList;
      import java.util.List;
      
      import javax.annotation.PostConstruct;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.SessionScoped;
      
      @ManagedBean
      @SessionScoped
      public class OverviewController implements Serializable{
          
          private static final long serialVersionUID = 544466031058458542L;
      
          private List<TableItem> tableItems;
          private String[] columnsOrder;
          
          @PostConstruct
          public void postConstruct() {
              System.out.println("start: postConstruct");
      
              tableItems = new ArrayList<TableItem>();
              tableItems.add(new TableItem("Oliver", "New York", "USA"));
              tableItems.add(new TableItem("Jane", "Washington", "USA"));
              tableItems.add(new TableItem("Fred", "Berlin", "Germany"));
              tableItems.add(new TableItem("Thomas", "London", "England"));
              
              columnsOrder = new String[] {"firstName", "city", "country" };
          }
          
          public void changeColumnsOrderWithAjax() {
              System.out.println("start: changeColumnsOrderWithAjax");
              
              changeColumnsOrder();
          }
          
          public String changeColumnsOrderFullRefresh() {
              System.out.println("start: changeColumnsOrderFullRefresh");
              
              changeColumnsOrder();
              
              return "";
          }
      
          private void changeColumnsOrder() {
              
              logColumnsOrder("before");
      
              if (columnsOrder[0].equals("firstName")) {
                  columnsOrder = new String[] {"country", "city", "firstName" };
              } else {
                  columnsOrder = new String[] {"firstName", "city", "country" };
              }
              
              logColumnsOrder("after");
          }
      
          private void logColumnsOrder(String logIdent) {
              
              System.out.println("logColumnsOrder " + logIdent);
              
              int idx = 0;
              System.out.println("logColumnsOrder, order is: ");
              for (String column : columnsOrder) {
                  System.out.println("column " + (idx++) + ": " + column);
              }
          }
      
          public List<TableItem> getTableItems() {
              return tableItems;
          }
          
          public void setTableItems(List<TableItem> tableItems) {
              this.tableItems = tableItems;
          }
      
          public String[] getColumnsOrder() {
              return columnsOrder;
          }
      
      }
      

       

      Table item:

       


      package org.richfaces.test.ak;
      
      
      public class TableItem {
          
          private String firstName;
          private String city;
          private String country;
          
          public TableItem() {
              
          }
          
          public TableItem(String firstName, String city, String country) {
              this.firstName = firstName;
              this.city = city;
              this.country = country;
          }
      
          public String getFirstName() {
              return firstName;
          }
          
          public void setFirstName(String firstName) {
              this.firstName = firstName;
          }
      
          public String getCity() {
              return city;
          }
          
      
          public void setCity(String city) {
              this.city = city;
          }
      
          public String getCountry() {
              return country;
          }
      
          public void setCountry(String country) {
              this.country = country;
          }
          
      }
      

       

      Best regards