2 Replies Latest reply on Aug 20, 2009 11:49 AM by Johannes Freudendahl

    changing extended data table selection

    Johannes Freudendahl Newbie


      I'm using an ExtendedDataTable on my page and have problems working with the selection. On the tree component, I can bind the selection to the backing bean and manipulate it there, e.g. select a newly inserted tree node before rerendering the tree. That works fine. If I try to do the same with my table, it seems I need the table component to make this work. Simply changing the SimpleSelection instance does not have the desired effect.

      For the record, I'm using RichFaces 3.3.1, MyFaces 1.2.5 and Facelets 1.1.14, with JDK 1.6 and Tomcat 6.0.18.

      My backend method is this:

       * Sets the table selection without the direct click on the table by the
       * user.
       * @param argRowIndex The row index to set, counted from 0. Use -1 to remove
       * the current selection.
       * @param argTable The table in which to set the row.
       private void setTableSelection(int argRowIndex, UIExtendedDataTable argTable) {
       SimpleRowKey newRowKey = null;
       SimpleSelection newSelection = null;
       // set the table selection
       if (argRowIndex >= 0) {
       newRowKey = new SimpleRowKey(argRowIndex);
       if (argTable != null) {
       newSelection = new SimpleSelection();
       } else {
       newSelection = new SimpleSelection();
       // makes the selection visible for the user
       if (argTable != null) {

      This would probably work if I had the table available, but unfortunately I don't. I can't bind the table to a property and get it from there, because the table is not serializable, but Spring Web Flow insists on serializing the stuff between calls. And I don't cal this method from a method which gets an event, so that I have any component.

      I guess what I'm asking is: Is there either a way to get the table component in my method instead of having it as an argument or is there else some other way to handle the binding and manipulating of the SimpleSelection instance so that a change in it shows up on rerender. Or is this simply a bug of the extended data table? ... I also just stumbled upon a similar method that I use for a ScrollableDataTable which works fine without having the table component.

      Anyway, any help would be greatly appreciated. Thanks!


        • 1. Re: changing extended data table selection
          Ilya Shaikovsky Master

          check out please the snapshot of RF demo there http://anonsvn.jboss.org/repos/richfaces/branches/community/3.3.X/samples/richfaces-demo and check extendedDataTAble sample. It's expanded with selection management. I'm using selection attribute bound to the backend property. And checked that if I change the selection from external action - table properly displays change.

          • 2. Re: changing extended data table selection
            Johannes Freudendahl Newbie

            Hi Ilya!

            Thanks a lot for your reply! It prompted me to finally install Maven, check out the demo application and play around with it a bit more. And you're correct, it works in the samples.

            Turns out, I made two errors. First, I set a SimpleRowKey instance as row key, which I probably did copy from the tree or somewhere else. In this case (an extended data table backed by an ArrayList) the row key was only an Integer instance. So my code from above works if you delete everything to do with the table component and add an Integer to the SimpleSelection instead of the SimpleRowKey instance.

            Also, it's no use to set a selection and then overwrite it with the default value before rerendering the view. But that was actually a problem with Spring Web Flow. ;-)

            Anyway, setting the selection without a click on the table works for now. I'll have a look into using a data model instead of the list though, because I understand that is better for use with sorting the table and using a paginator component!? By the way, there's not really much in the documentation, I think, about using your own data model rather than a collection. Probably something that could be expanded.

            Thanks for the help!