2 Replies Latest reply on May 27, 2010 11:16 PM by shanika Dias

    rich:extendedDataTable with select all rows functionality via a check box

    shanika Dias Newbie

      Hi,

       

      I am having a extendedDataTable and i'm trying to do a select all via a check box that's outside the table.  When a user clicks on the check box to select all, all the records must get selected.

       

      Everything works fine until i use the select all check box to select all records and then  ctrl + mouse click to deselect a row. Though the clicked row gets deselected in the gui, my takeSelection() method returns 0 records though the rest of the records are shown as selected in the gui.

       

      here's the code :

       


      <h:selectBooleanCheckbox id="checkBoxSelection" value="#{ToDo.selectAllClicked}" title="Select All">
         <a:support event="onclick" action="#{ToDo.selectAllValueChanged()}" ajaxSingle="true" reRender="toDoListPanel"/>

      </h:selectBooleanCheckbox>

       

      ...


      <a:outputPanel id="toDoListPanel">

                <rich:extendedDataTable id="toDoTable" value="#{itemsToDo}" var="todo" headerClass="thfmt" style="width:100%;" 

                  selectionMode="multi" selection="#{ToDo.selection}" rendered="#{itemsToDo.rowCount > 0}">

                ....

                ....

       

               <a:support event="onselectionchange" ignoreDupResponses="true" requestDelay="500" ajaxSingle="true" action="#ToDo.takeSelection}" />

               </rich:extendedDataTable>
      </a:outputPanel>

       

       

       

      in my java code :

       


      private ArrayList<RuleVersion> selectedItems = new ArrayList<RuleVersion>();

      private SimpleSelection selection = new SimpleSelection();  

      private boolean selectAllClicked = false;

       

       

      public String takeSelection() {      
             selectedItems.clear();
             Iterator<Object> iterator = getSelection().getKeys();
               
             while (iterator.hasNext()) {
                 Object key = iterator.next();

                 selectedItems.add(todo.get(Integer.parseInt(key.toString())));        
             }     
            
             return null;
          }
         
          public void selectAllValueChanged(){
                
             selection.clear();
             selection.setSelectAll(selectAllClicked);     
             
          // If all selected copy all else clear all items
            if (selectAllClicked == true){ 
               for (RuleVersion r : todo){
                   selectedItems.add(r);
               }
            }else{
               selectedItems.clear();
            }
          
          }

       

      What am i missing here?

       

      -shanika