3 Replies Latest reply: Apr 21, 2013 3:49 AM by Michael Shapira RSS

    scrolling rich table programatically

    Michael Shapira
      Jdev 11 g R2

      Hi. I am trying automatically scroll the table to specific row.
      I found a good example in ADF corner which shows how to scroll to a row by number
      [Link to example|http://www.oracle.com/technetwork/developer-tools/adf/learnmore/28-ctrl-g-table-scrolling-169170.pdf]
      It is very simple (I think it was written by Frank)
      Here is the table

      <af:form id="f1">
      <af:table value="#{bindings.EmployeesView1.collectionModel}" var="row"
      rows="#{bindings.EmployeesView1.rangeSize}"
      emptyText="#{bindings.EmployeesView1.viewable ? 'No data to display.' : 'Access Denied.'}"
      fetchSize="#{bindings.EmployeesView1.rangeSize}"
      rowBandingInterval="0"
      selectedRowKeys="#{bindings.EmployeesView1.collectionModel.selectedRow}"
      selectionListener="#{bindings.EmployeesView1.collectionModel.makeCurrent}"
      rowSelection="single" id="t1"
      inlineStyle="height:190px; width:400.0px;"
      displayRow="selected" binding="#{SearchRowBean.table1}">
      <af:column sortProperty="DepartmentId" sortable="false"
      headerText="#{bindings.EmployeesView1.hints.DepartmentId.label}"
      id="c4">
      <af:outputText value="#{row.DepartmentId}" id="ot5"
      clientComponent="false">
      <af:convertNumber groupingUsed="false"
      pattern="#{bindings.EmployeesView1.hints.DepartmentId.format}"/>
      </af:outputText>
      </af:column>
      <af:column sortProperty="EmployeeId" sortable="false"
      headerText="#{bindings.EmployeesView1.hints.EmployeeId.label}"
      id="c5">
      <af:outputText value="#{row.EmployeeId}" id="ot1">
      <af:convertNumber groupingUsed="false"
      pattern="#{bindings.EmployeesView1.hints.EmployeeId.format}"/>
      </af:outputText>
      </af:column>

      <af:column sortProperty="Email" sortable="false"
      headerText="#{bindings.EmployeesView1.hints.Email.label}"
      id="c2">
      <af:outputText value="#{row.Email}" id="ot3"/>
      </af:column>
      <af:clientListener type="keyDown" method="launchTableRowScroller"/>
      </af:table>
      <af:commandButton text="commandButton 1" id="cb2" action="#{SearchRowBean.goTo}"/>

      </af:form>


      And here the code that scrolls the table

      CollectionModel collectionModel = (CollectionModel)table1.getValue();
      //the table model - CollectionModel - wraps the ADF tre binding for this table
      JUCtrlHierBinding tableBinding = (JUCtrlHierBinding) collectionModel.getWrappedData();
      //get the iterator for the tree binding
      DCIteratorBinding iteratorBinding = tableBinding.getIteratorBinding();
      //from the table instance itself, get the requested row number
      JUCtrlHierNodeBinding rowBinding = (JUCtrlHierNodeBinding) table1.getRowData(rowNumber-1);
      //from the node binding, get the JBO rowKey
      Key rowKey = rowBinding.getRow().getKey();
      //make the searched row the current
      iteratorBinding.setCurrentRowWithKey(rowKey.toStringFormat(true));
      //create a new table rowKey (the RichTable row key is different from JBO Key
      ArrayList tableRowKey = new ArrayList();
      tableRowKey.add(rowKey);
      RowKeySetImpl rks = new RowKeySetImpl();
      rks.add(tableRowKey);
      table1.setSelectedRowKeys(rks);
      //close the search dialog
      closePopup("p1");
      //refresh table
      AdfFacesContext.getCurrentInstance().addPartialTarget(table1);

      It works just fine!!!!

      And here is my code.
      The only different is that my table is located in the page fragment and wrapped by panel collection and is part of the bounded task flow and this flow appears as a region on the another JSPX page

      Here is my table

      <f:facet name="second">

      <af:panelCollection id="pc1">
      <f:facet name="menus"/>
      <f:facet name="toolbar"/>
      <f:facet name="statusbar"/>

      <af:table value="#{bindings.customers.collectionModel}" var="row"
      rows="#{bindings.customers.rangeSize}"
      emptyText="#{bindings.customers.viewable ? 'No data to display.' : 'Access Denied.'}"
      fetchSize="#{bindings.customers.rangeSize}"
      rowBandingInterval="0"
      selectionListener="#{bindings.customers.collectionModel.makeCurrent}"
      rowSelection="single" id="t1"
      binding="#{scrol_lbean.t1}"
      inlineStyle="height:190px; width:400.0px;"
      selectedRowKeys="#{bindings.customers.collectionModel.selectedRow}"
      displayRow="selected"
      >






      <af:column sortProperty="#{bindings.customers.hints.customerName.name}" sortable="false"
      headerText="#{bindings.customers.hints.customerName.label}" id="c1">
      <af:outputText value="#{row.customerName}" id="ot1"/>
      </af:column>
      <af:column sortProperty="#{bindings.customers.hints.customerId.name}" sortable="false"
      headerText="#{bindings.customers.hints.customerId.label}" id="c2">
      <af:outputText value="#{row.customerId}" id="ot2"/>
      </af:column>
      </af:table>

      </af:panelCollection>

      </f:facet>

      And here is my code, which is basically the same as the code above.

      public String goToLine()
      {
      int rowNumber = Math.abs( new Random().nextInt()%90)+1;
      RichTable table1 = getT1();
      //get the table model
      CollectionModel collectionModel = (CollectionModel)table1.getValue();
      //the table model - CollectionModel - wraps the ADF tre binding for this table
      JUCtrlHierBinding tableBinding = (JUCtrlHierBinding) collectionModel.getWrappedData();
      //get the iterator for the tree binding
      DCIteratorBinding iteratorBinding = tableBinding.getIteratorBinding();
      //from the table instance itself, get the requested row number
      JUCtrlHierNodeBinding rowBinding = (JUCtrlHierNodeBinding) table1.getRowData(rowNumber-1);
      //from the node binding, get the JBO rowKey
      Key rowKey = rowBinding.getRow().getKey();
      //make the searched row the current
      iteratorBinding.setCurrentRowWithKey(rowKey.toStringFormat(true));
      //create a new table rowKey (the RichTable row key is different from JBO Key
      ArrayList tableRowKey = new ArrayList();
      tableRowKey.add(rowKey);
      RowKeySetImpl rks = new RowKeySetImpl();
      rks.add(tableRowKey);
      table1.setSelectedRowKeys(rks);


      AdfFacesContext.getCurrentInstance().addPartialTarget(table1);
      return null;
      }

      I click a button which generates random number in the range of the number of rows and make it selecteble.
      Indeed the table row becomes selected, but the table IS NOT SCROLLED TO THIS ROW. So if I scroll by scroller I do see the selected line

      Please help to understand why my table is not being scrolled to selected row

      Edited by: Michael Shapira on Apr 19, 2013 2:46 AM