Uploaded image for project: 'RichFaces'
  1. RichFaces
  2. RF-12004

rich:dataTable. DataModel data & rowIndex are not synchronized when using breakRowBefore

    Details

    • Steps to Reproduce:
      Hide
      brokenTable.xhtml
      <rich:dataTable value="#{backingBean.rows}" var="logicalRow">
        <rich:column>
          <h:outputText value="#{logicalRow[0]}"/>
        </rich:column>
        <rich:column breakRowBefore="true">
          <h:outputText value="#{logicalRow[1]}"/>
        </rich:column>
        <a4j:ajax event="rowclick" listener="#{backingBean.rowClickHandler}"/>
      </rich:dataTable>
      
      BackingBean.java
      public class BackingBean {
        private String[][] rows = {
          { "a-1", "a-2" }
        };
        public String[][] getRows() {
          return rows;
        }
        public void rowClickHandler(AjaxBehaviorEvent event) {
          UIDataTable dataTable = (UIDataTable) event.getComponent();
          System.out.println("Row index    : " + dataTable.getRowIndex());
          System.out.println("Row available: " + dataTable.isRowAvailable());
          System.out.println("Row data     : " + dataTable.getRowData()); //May cause exception
      }
      

      Note: Row filter usage haven't been tested and may cause more unexpected behavior.

      Show
      brokenTable.xhtml <rich:dataTable value= "#{backingBean.rows}" var = "logicalRow" > <rich:column> <h:outputText value= "#{logicalRow[0]}" /> </rich:column> <rich:column breakRowBefore= " true " > <h:outputText value= "#{logicalRow[1]}" /> </rich:column> <a4j:ajax event= "rowclick" listener= "#{backingBean.rowClickHandler}" /> </rich:dataTable> BackingBean.java public class BackingBean { private String [][] rows = { { "a-1" , "a-2" } }; public String [][] getRows() { return rows; } public void rowClickHandler(AjaxBehaviorEvent event) { UIDataTable dataTable = (UIDataTable) event.getComponent(); System .out.println( "Row index : " + dataTable.getRowIndex()); System .out.println( "Row available: " + dataTable.isRowAvailable()); System .out.println( "Row data : " + dataTable.getRowData()); //May cause exception } Note: Row filter usage haven't been tested and may cause more unexpected behavior.
    • Workaround:
      Workaround Exists
    • Workaround Description:
      Hide

      You must consider getRowIndex() as physical row index and correctly map it on logical row.

      Here's an example assuming rows are always break once :

      BackingBean.java
        public void rowClickHandler(AjaxBehaviorEvent event) {
          UIDataTable dataTable = (UIDataTable) event.getComponent();
          int physicalRowIndex = dataTable.getRowIndex();
          if (physicalRowIndex >= 0) {
            int logicalRowIndex = physicalRowIndex/2;
            // Puts your code here
          }
        }
      

      Note: Row filter usage haven't been tested and may cause more unexpected behavior.

      Show
      You must consider getRowIndex() as physical row index and correctly map it on logical row. Here's an example assuming rows are always break once : BackingBean.java public void rowClickHandler(AjaxBehaviorEvent event) { UIDataTable dataTable = (UIDataTable) event.getComponent(); int physicalRowIndex = dataTable.getRowIndex(); if (physicalRowIndex >= 0) { int logicalRowIndex = physicalRowIndex/2; // Puts your code here } } Note: Row filter usage haven't been tested and may cause more unexpected behavior.

      Description

      When activating breakRowBefore, the rowIndex of DataTable is using physical row (TR tag) where as rowData is using logical row.

      It causes the following incorrect behaviors (when selecting a valid line) :
      if physical row index is greater than (or equal to) logical row count

      • isRowAvailable() returns false
      • getRowData() throws NoRowAvailableException
      • Using both getRowIndex() and source data (ie from a backing-bean) causes RowIndexOutOfBoundException

      if physical row index is lower than logical row count and greather than zero

      • getRowData() doesn't return the matching row data
      • Using both getRowIndex() and source data (ie from a backing-bean) doesn't return the matching row data

      Note: Row filter usage haven't been tested and may cause more unexpected behavior.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                logan.mauzaize.infotel.com Logan M
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated: