8 Replies Latest reply on Nov 15, 2012 11:11 AM by davidbatteux

    ExtendedDataTable unselect all with partial rerender

    doboss

      I have an extended data table with about 10 columns and multiple-selection enabled. Selecting and unselecting by clicking on the table works great, but I would like to add a button which clears all the selected lines at once but without rerendering the entire table. (Not the contents, just the highlighted/selected rows)

       

      My table looks like this:

       

       

      <rich:extendedDataTable id="table" value="#{bean.lineItemModel}"

                     var="lineItem" rows="#{bean.rowsPerPage}"

                     ajaxKeys="#{bean.rowsToUpdate}"

                     selection="#{bean.selection}">

       

       

       

           <rich:column id="c1" sortable="true" sortBy="#{lineItem.descrip}" filterBy="#{lineItem.descrip}"

                        label="Description">

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

                        <h:outputText value="#{lineItem.descrip}" />

                     </rich:column>

      ...

      </rich:extendedDataTable>

       

       

      I then have a button which is supposed to clear all the slected rows:

       

      <a:commandButton value="Clear Selected" style="float: right;" action="#{bean.clearSelectedItems}"

                                   ajaxSingle="true" reRender="c1,c2,c3,c4,c5,c6,c7,c8,c9,c10"

                                    title="Use this button to clear the line items that have been selected." />

       

      And my bean looks like this:

       

      ...

         private SimpleSelection selection = new SimpleSelection();

         private final LinkedHashSet<LineItem> rowsToUpdate = new LinkedHashSet<LineItem>();

      ...

         public SimpleSelection getSelection()

         {

            return selection;

         }

       

         public void setSelection(SimpleSelection selection)

         {

            this.selection = selection;

            rowsToUpdate.clear();

         }

       

         private void setupRowsToUpdateFromSelection()

         {

            rowsToUpdate.clear();

            for (Iterator<Object> iterator = selection.getKeys(); iterator.hasNext();)

            {

               LineItem item = (LineItem) iterator.next();

               rowsToUpdate.add(item);

            }

         }

       

         public Set<LineItem> getRowsToUpdate()

         {

            return rowsToUpdate;

         }

       

         public void clearSelectedItems()

         {

            // Set the rows to update before clearing the selection (so they rerender)

            setupRowsToUpdateFromSelection();

            this.selection.clear();

         }

       

      The expected behavior is that when I click the "Clear Selected" button, all the selected rows will be unselected, and only that part of the table will be rerendered. But when I click it, the code is called, but the rows remain highlighted/selected.

       

      I have other code which uses the row level rerendering based on the ajaxKeys and rowsToUpdate, and that all works fine. I've stepped through the code in the debugger, and clearSelectedItems is being called before getRowsToUpdate is called, and getRowsToUpdate is returning the right rows. If I rerender the whole table, the rows are unselected as expected, but I do not want to rerender the whole table because it is slow.

       

      Using FireBug it does look like the Ajax-Update-Ids contains the right list of components to update...

       

      Am I missing something, or is it not possible to do what I am trying to do.

       

      Thanks!