3 Replies Latest reply on Feb 17, 2012 4:00 PM by lobo369

    Cannot retrieve row index in ExtendedTableDataModel

    kang2012

      Hi,

      I'm using rich:extendedDataTable with ExtendedTableDataModel in my backing bean.  I've also attached a rich:dataScroller to my table.  My main question is, the "getRowIndex()" method of the dataModel returns null.  I realize the docs say this variable is "unused", so what's the latest and greatest way of getting the row Index?  I've tried to calculate it using the DataProvider to get the index in the list of data items, but that's not helpful when sorting/filtering changes the order. 

       

      Essentially, I need this index to calculate which page I should jump to with the datascroller.  I want the user to see the page that contains a particular row (my logic for getting that row key is not relevant).  I know another way is to set the selected row from the back end using SimpleSelection, but the problem is that I'm not sure how to calculate the page that would contain the selected row. 

       

      I believe I'm using the model correctly, because I'm able to setRowKey/getRowData without any issues.

       

      If I can get the dataTableModel.getRowIndex(), that'd be the best solution.  And I've seen other suggestions saying to set it to -1 when creating the model, but all that does is avoid the Null pointer exception.  The row index never increments.  And I don't want to make my own "manual increment" method, because that doesn't actually align with the richness of the extendedTableDataModel.

       

       

      Thanks

        • 1. Re: Cannot retrieve row index in ExtendedTableDataModel
          pvito

          Hi, KA NG

           

          Try use iterationStatusVar attribute to retrive row index:

          <h:form>

              <rich:dataScroller for="table" maxPages="5" />

              <rich:extendedDataTable value="#{myBeen.list}" var="v" iterationStatusVar="isv" id="table" rows="5">

                 

                 

                  <rich:column>

                      <f:facet name="header">0</f:facet>

                     #{isv.index}

                  </rich:column>

                 

                 

                   <rich:column>

                       <f:facet name="header">1</f:facet>

                       #{v.value1}

                   </rich:column>

                  <rich:column>

                      <f:facet name="header">2</f:facet>

                      #{v.value2}

                  </rich:column>

           

              </rich:extendedDataTable>

          </h:form>

          Regards, Vitaliy

          • 2. Re: Cannot retrieve row index in ExtendedTableDataModel
            kang2012

            Hi Vitaliy,

             

            Thanks for your reply.  IterationStatusVar only works for dataTable, not extendedDataTable.  Also, this would be helpful for displaying the index in the table.  I need the indexes of the backing extendedTableDataModel, so that I'll get the correct index of a particular rowKey when the order of the table changes.   I need to know where a particular row will end up in the table after sorting using Asc/Desc arrows.

            • 3. Re: Cannot retrieve row index in ExtendedTableDataModel
              lobo369

              Hi KA NG

               

              If you want to retrieve the row index of the selected row you need to set binding parameter of the ExtendedDataTable to a variable of type javax.faces.component.UIData.

               

              Then in your action you use UIData to retrive the row [getRowData()] or the index [getRowIndex()].