5 Replies Latest reply on May 30, 2008 2:01 PM by Phil Wilson

    ScrollableDataTable multiple and single row selection config

    Brian Dillon Newbie

      Hi,

      The RichFaces ScrollableDataTable supports multiple and single row selection. How is this configured ? Currently I can only get it to work with multiple selection.

      Thanks,

      Brian

        • 1. Re: ScrollableDataTable multiple and single row selection co
          Victoria S Newbie

          Hi bdillon,

          Can I ask how you managed to make it multi-selectable?? Only I've been struggling with this for some time!

          Thanks
          Victoria

          • 2. Re: ScrollableDataTable multiple and single row selection co
            Brian Dillon Newbie

            Victoria,

            The table allows multiple selection by default. I presume that your issue is with the 'selection' attribute ?

            Anyway if this is what the issue is then this is how I got it working with our stuff;

            In the xhtml specify the selection attribute to reference an attribute on your backing bean.

            <rich:scrollableDataTable ......... value="${dataList}" selection="#{backingBean.selection}">

            In the backing bean have something like ;

            public class DataTableBB {


            List dataList;/** List of the Data to Display **/

            //List of the rows which are selected !
            List selectRows = new ArrayList();

            /**
            * Get the RichFaces SimpleSelection object (used to store row selections)
            * Called by RichFaces framework !
            * @return SimpleSelection
            */
            public SimpleSelection getSelection() {
            return new SimpleSelection();
            }

            /**
            * Set the RichFaces SimpleSelection object
            * Called by RichFaces framework !
            * @param selection
            */
            public void setSelection(SimpleSelection selection) {
            Iterator iterator = selection.getKeys();
            while (iterator.hasNext()){
            SimpleRowKey key = iterator.next();
            //Add the selected row to the list
            selectRows.add(key.intValue());
            // if you wish to access the data for this row you could call
            // dataList.get(key.intValue())
            // and add that to a diffent list
            }
            }


            I originally looked at maintaining the SimpleSelection object as the variable (see the following example https://labs.jboss.com/authsec/wiki/en//RichFacesCookbook/ScrollableDataTableSelectionUsage ) but kept getting Serialization exceptions so needed to work around it.

            Thanks,

            Brian

            • 3. Re: ScrollableDataTable multiple and single row selection co
              Victoria S Newbie

              Hi Brian,

              Thank you. That makes more sense than the binding="", which was throwing the error you mentioned. I hadn't even noticed that you could select many rows.. (blonde moment). I can't seem to find a single select option in the docs, but I have effectively made it single select by wiping the ArrayList on every iteration (Could just use: Packet selectedPacket = new Packet();)

              Iterator iterator = selection.getKeys();
               while (iterator.hasNext())
               {
               SimpleRowKey key = (SimpleRowKey) iterator.next();
               //Add the selected row to the list
               //selectRows.add(key.intValue());
               // if you wish to access the data for this row you could call
               selectedPackets = new ArrayList<Packet>();
               selectedPackets.add( this.matchingPackets.get(key.intValue()) );
               }
              

              This would probably confuse the user though.
              One major disadvantage of the SimpleSelection is that it seems to be a click behind? I click on line 4 (for example) and it tells me nothing is selected. Next I click on line 8 and it tells me 4 is selected...
              I am using the SimpleSelection along with the <a4j:support tag though, so I do have the current selected row from the support tag.

              Thank you
              Victoria

              • 4. Re: ScrollableDataTable multiple and single row selection co
                Phil Wilson Apprentice

                Hi Brian and Victoria,

                How did you fix your issue with single select?

                I ask this because I have the same issue. I have a datagrid and would like to allow user to delete selected rows.

                Thanks
                Phil

                • 5. Re: ScrollableDataTable multiple and single row selection co
                  Phil Wilson Apprentice

                  Any help out there??

                  Selection on a dataGrid??

                  Phil