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

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

    shanikaweerapperuma

      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

        • 1. Re: rich:extendedDataTable with select all rows functionality via a check box
          ilya_shaikovsky

          Hi,

           

          please try not to use selection.setSelectAll(selectAllClicked); at all and just add all items to selection set in selectBox action.

          • 2. Re: rich:extendedDataTable with select all rows functionality via a check box
            shanikaweerapperuma

            Hi Ilya,

             

            Thank you very much. I really appreciate all your efforts to answer many questions like this everyday.

             

            Now it works fine after following your instructions ( Now i use selection.addKey method to add all rows to the selection as below)  :

             

            public void selectAllValueChanged(){
                         
                   selectedRuleVersions.clear();
                   selection.clear();    
                  
                   // If all selected copy all
                   if (selectAllClicked == true){
                      int i = 0;
                      for (RuleVersion r : todo){
                          selectedRuleVersions.add(r);
                          selection.addKey(i++);
                      }         
                      
                 }
                
            }

             

             

            Regards

            Shanika