2 Replies Latest reply on Sep 22, 2012 10:55 AM by Robert Peake

    ExtendedDataTable:  reset row selection on loading new data

    Robert Peake Newbie

      Concept: A search page is used to locate entries in a database. An entry can then be selected for editing by clicking on the row.

       

      Problem: A selection change is not fired when two successive queries both return a single entry.

       

      Example: A search is performed on the title "AAA".  A single matching record is returned.  Clicking on the row selects it (text bcomes bold) and the selectionListener logs the selection:  

      INFO: selectionListener: row key = 0

      INFO: selectionListener: entry = AAA

       

      A second search is performed on the title "BBB".  Again, a single matching record is returned and clicking on the row selects it (text bcomes bold).  However, no selectionchange event is fired and no log entry is generated.

       

      The problem occurs when the second record is loaded.  Although the data table does not visually indicate a selected row (text is not bold) the table state has not been reset to an unselected condition.  Apparently, as far as the table is concerned, the row selection (row 0) has not changed so it does not fire the selectionchange event.

       

      The obvious solution is to re-initialize the table (that is, set it to the state it was in when the page was first loaded), but I have been unable to find out how to do this.  It seem to be a bug (or at least an oversight).  The data table retains the last row selected and even when new data is loaded, will not fire a selectionchange event if the user selects that same row.  This is a minor problem when multiple rows are returned, but major when the query returns a single result and the user cannot select another row to force a selectionchange.

       

      Here is the pertinent code.

       

      xhtml:

       

      <rich:extendedDataTable id="edt" width="700px" height="500px"

                  value="#{findTest.entryList}" var="entry"

                  rowKeyVar="rowKey" selectionMode="single"               

                  selection="#{findTest.selection}" >               

                   <a4j:ajax event="selectionchange" render="edt edit out"

                      listener="#{findTest.selectionListener}" />

                  <rich:column>

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

                      #{entry.nbr}           

                  </rich:column>   

                  <rich:column width="200px">

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

                      #{entry.title}

                  </rich:column>

              </rich:extendedDataTable>

       

      and the selectionListener:

       

      public void selectionListener(AjaxBehaviorEvent event) {

              UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();

              editEntryList.clear();

              for (Object selectionKey: selection) {

                  Logger.getLogger("controller").log(Level.INFO,

                          "selectionListener: row key = " + selectionKey);

                  dataTable.setRowKey(selectionKey);

                  if (dataTable.isRowAvailable()) {

                      entry = (Entry)dataTable.getRowData();               

                      Logger.getLogger("controller").log(Level.INFO,

                          "selectionListener: entry = " + entry.getTitle());

                      editEntryList.add(entry);

                  }

              }

          }

       

      This should be simple enough to remedy in a release (simply set the rowKey to some non-row value such as null or -1 when new data loads).  I have not seen any other reports of the problem.

       

      I am using version 4.3.0.20120802-M1 on a Windows 7 64-bit platform.

       

      I have not found a workaround and would be grateful for any suggestions.