1 2 Previous Next 15 Replies Latest reply on Oct 2, 2007 2:45 PM by Samuel Doyle

    ScrollableDataTable and selection

    Samuel POSSEME Newbie

      Hi,
      I'm trying to retrieve the selected (unique) row on my ScrollableDataTable. In the doc, i see that there's a binding value for "selection" but it's still null.
      I tried to getSelection() on UIScrollableDataTable object (binding my table), but i can't use iterator retieved by getKeys() method because it gives a SimpleRowKey instance (unusable cause it's an embedded class).

      Moreover, the method used with datatable (getting rowData) doesn't work either.
      Can anyone explain me how to retrieve my selection ?

      My code :

      <h:form>
       <rich:scrollableDataTable rows="5"
       width="317px" binding="#{testdata.itemsBind}" rowKey="rkv"
       height="100px" var="item" value="#{testdata.itemsList}" selection="#{testdata.currentitem}">
      
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Code Article" />
       </f:facet>
       <h:outputText value="#{item.citem}"></h:outputText>
       </rich:column>
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Libellé" />
       </f:facet>
       <h:outputText value="#{item.litem}"></h:outputText>
       </rich:column>
       <rich:column>
       <f:facet name="header">
       <h:outputText value="Libellé réduit" />
       </f:facet>
       <h:outputText value="#{item.rlitem}"></h:outputText>
       </rich:column>
      
       </rich:scrollableDataTable>
       <h:commandButton action="#{testdata.doAction}" value="Envoi la sauce"/>
       </h:form>


        • 1. Re: ScrollableDataTable and selection
          Maksim Kaszynski Apprentice

          hoedic,

          Does this work for you?

          keys = selection.getKeys();
          while(keys.hasNext()) {
           Object key = keys.next();
           table.setRowKey(key);
           Object data = table.getRowData();
          }


          • 2. Re: ScrollableDataTable and selection
            Samuel POSSEME Newbie

            Yes !
            That's do it,
            thank you so much.

            • 3. Re: ScrollableDataTable and selection
              Matthias Graehn Newbie

              Hi hoedic,

              could you please post your backing bean I do have the same problem and a piece is still missing in the puzzle.

              Thanks

              Matt

              • 4. Re: ScrollableDataTable and selection
                Matthias Graehn Newbie

                Could someone pleas help me with this.

                What is the type of the value binding selection? And how do I bind this to
                <rich:scrollableDataTable selection="#{testdata.currentItem}".

                With this method Binding:

                 public Object getCurrentItem(){
                 Selection selection = table.getSelection();
                 Object data=null;
                 Iterator keys = selection.getKeys();
                
                 while(keys.hasNext()) {
                 Object key = keys.next();
                 table.setRowKey(key);
                 data = table.getRowData();
                 System.out.println("Selected: " + data.getClass().toString());
                 }
                 return data;
                 }
                


                I got a strage exception that seems to have nothing to do with it but if I
                comment out the selection=... the table shows up and the exception does
                not appear.

                java.util.MissingResourceException: Can't find bundle for base name javax.el.LocalStrings, locale de_DE
                 at java.util.ResourceBundle.throwMissingResourceException(Unknown Source)
                 at java.util.ResourceBundle.getBundleImpl(Unknown Source)
                 at java.util.ResourceBundle.getBundle(Unknown Source)
                 at javax.el.ELResolver.message(ELResolver.java:40)
                


                Tried to check what type selection.getKeys(); returns but only got the
                following error in eclipse error log:

                Unknown javadoc format for Selection {key=Lorg/richfaces/model/selection/Selection;} [in Selection.class [in org.richfaces.model.selection [in WebContent/WEB-INF/lib/richfaces-api-3.1.1-SNAPSHOT.jar [in fineo.elso]]]]
                


                What does this mean?

                Regards

                Matt

                • 5. Re: ScrollableDataTable and selection
                  Maksim Kaszynski Apprentice

                  Matt, you just get StackOverflow.
                  selection="#{testdata.currentItem}" calls for your getter,
                  public Object getCurrentItem(), which in turn calls for table.getSelection().
                  Guess, what last method does? I evaluates selection="#{testdata.currentItem}", and you get infinite loop

                  • 6. Re: ScrollableDataTable and selection
                    Matthias Graehn Newbie

                    How does it work, then? There is neigher concrete description nor an example how to get selection of scrollableDataTable in Developer Guide or Online Demo.

                    • 7. Re: ScrollableDataTable and selection
                      Matthias Graehn Newbie

                      Am I the only one who use section on scrollableDataTable?

                      • 8. Re: ScrollableDataTable and selection
                        Zac Wolfe Newbie

                        I'm running into the same problem. I see that it's possible to achieve the same effect by iterating over selection.getKeys() but isn't that what the "selection" binding var is for?

                        • 9. Re: ScrollableDataTable and selection
                          Jon Zuccaro Newbie

                          looks like we are alone with this problem, I can't figure out how to get a selected Row with this component

                          • 10. Re: ScrollableDataTable and selection
                            Zac Wolfe Newbie

                            Since I couldn't get the selection attribute to work I ended up just using ajax4jsf support to call an actionListener method whenever the selection changes:

                            <rich:scrollableDataTable....>
                            ...
                            <a4j:support event="onselectionchange" actionListener="#{myBean.selectionChanged}" />
                            
                            </rich:scrollableDataTable>
                            


                            Then from the actionListener method you can pull out the selected values from the list:

                            public void selectionChanged(ActionEvent e) throws AbortProcessingException {
                            
                             HtmlScrollableDataTable table = (HtmlScrollableDataTable) ((HtmlAjaxSupport) e.getComponent())
                             .getParent();
                             Selection sel = table.getSelection();
                             List selected = new ArrayList();
                             for (Iterator iter = sel.getKeys(); iter.hasNext();) {
                             Object next = iter.next();
                             table.setRowKey(next);
                             selected.add(table.getRowData());
                             }
                            
                             this.currentSelection = selected;
                             }
                            


                            It works fine for me but I still wish I could get the selection attribute working and avoid this ugliness.

                            • 11. Re: ScrollableDataTable and selection
                              Maksim Kaszynski Apprentice

                               

                              "zacwolfe" wrote:
                              I'm running into the same problem. I see that it's possible to achieve the same effect by iterating over selection.getKeys() but isn't that what the "selection" binding var is for?


                              Selection binding should point to field of type org.richfaces.model.selection.Selection. It is read-write, i.e. component loads selection from that binding, and when selection has been changed writes the selection there.

                              • 12. Re: ScrollableDataTable and selection
                                Maksim Kaszynski Apprentice

                                Selection doesn't contain selected objects themselves, but their keys.

                                • 13. Re: ScrollableDataTable and selection
                                  Brian Dillon Newbie

                                  Hi,

                                  I have come across this as well and was wondering is there a recommended way of using the ScrollableDataTable selection utility ?

                                  Currently what I have is;

                                  <rich:scrollableDataTable rowKeyVar="rkv" ....
                                  selection="#{myBean.selectedRow}">

                                  In the backing bean I have the following;

                                  private Selection selectedRow;

                                  public Selection getSelectedRow() {
                                  System.out.println(" Get Selected row called");
                                  return selectedRow;
                                  }

                                  public void setSelectedRow(Selection selectedRow) {
                                  System.out.println(" Number of selected rows "+selectedRow.size());
                                  this.selectedRow = selectedRow;
                                  }

                                  However what I have encountered is that the number of selected rows is 0 ! Is there a step I am missing or am I simple using this incorrectly ?

                                  Thanks,

                                  Brian

                                  • 14. Re: ScrollableDataTable and selection
                                    Samuel Doyle Apprentice

                                    Bumping this to the top. I also would like to know the answer to this. Although based on the level of support on this board I am highly doubtful we will get an answer from someone internal.

                                    1 2 Previous Next