1 2 Previous Next 18 Replies Latest reply on Apr 21, 2010 6:03 AM by ilya_shaikovsky

    scrollableDataTable issues with selecting rows

    baz

      Hello,
      the documentation for scrollableDataTable (RF3.1.2GA) states as a keyfeature of scrollableDataTable:

      One and multi-selection rows mode

      But i have not managed to get this to work.
      And i have not found an example for using this feature nor a documentation for it.

      Does it work right now? And how is it used? Any example or documentation is really appreciated.

      According to the docs there should be an attribute "selection"
      But how is it used?

      Ciao,
      Carsten

        • 1. Re: scrollableDataTable issues with selecting rows
          baz

          The visual selection with the mouse does work. But how can i access the selected rows?

          • 2. Re: scrollableDataTable issues with selecting rows
            j-pro

            add this to your scrollableDataTable tag:

            binding="#{bean.table}" selection="#{bean.selection}"


            Add this(with appropriate getters and setters) into your bean(backing bean class):
            private Selection scrollableDataTableSelection;
             private HtmlScrollableDataTable sdTable;


            And you can make this in your action listener:
            public void listener(ActionEvent event)
            {
            
             Iterator keys = table.getKeys();
            
             while(keys.hasNext())
             {
             Object key = keys.next();
             table.setRowKey(key);
             Object rowData = table.getRowData();
            
             // here do what you want with your rowData
            
             }
            }


            • 3. Re: scrollableDataTable issues with selecting rows
              j-pro

              In the text above:

              scrollableDataTableSelection = selection
              sdTable = table

              (just pasted from my code)

              • 4. Re: scrollableDataTable issues with selecting rows
                baz

                Thanks, i try it out.
                Just one question left:
                Is selection independent from binding?
                or with other words: can i just specify the selection attribute without the binding?
                Ciao,
                Carsten

                BTW: (i am open to discus my standpoint)
                I do not like to use component bindings within my application beans. And with JBoss seam i have to introduce one more pojo in request scope, only to get the binding working.

                But this,surely, depends on the developers point of view.
                For me, all component depend code has to go into the component. The application developer should have no need to use the binding attribute.

                • 5. Re: scrollableDataTable issues with selecting rows
                  ykravchenko

                  Hi all, I have exactly same problem.

                  My selection attribute binding doesn't work even when I perform table binding (table binding works Ok).

                  I'm using richfaces-3.1.0 and jsf 1.1 (Sun impl.) When I run server in debug mode it's clear that cause or problem is Selection property of bean not being mapped.

                  HtmlScrollableDataTable has getSelected() method, tried to use it in following way

                  Iterator keys = table.getSelection().getKeys();

                  while(keys.hasNext())
                  {
                  Object key = keys.next();
                  table.setRowKey(key);
                  Object rowData = table.getRowData();

                  // here do what you want with your rowData

                  }


                  Even when I have selected row Iterator seems to be "empty"

                  Dear J-Pro could You suggest something, maybe some sort of additional attribute is needed?

                  • 6. Re: scrollableDataTable issues with selecting rows
                    baz

                    Hello,
                    i have tried the solution J-Pro suggested.
                    But when i do this:

                    binding="#{bean.table}" selection="#{bean.selection}"

                    an exception is raised that states that bean.selection is of wrong type. Unfortunately, i do not have the stacktrace anymore. But if the stacktrace is important, i will generate it again.

                    Is there a complete example for selection of entities in a scrollableDatatable? This could be of more help for all of us.

                    • 7. Re: scrollableDataTable issues with selecting rows
                      ykravchenko

                      Strange baz cause I had no exception thrown, just binding didn't occur. my selection property was still null

                      • 8. Re: scrollableDataTable issues with selecting rows
                        holstead

                        HtmlScrollableDataTable.getKeys() doesn't exist.

                        Richfaces 3.1.1

                        What version should I be using?

                        • 9. Re: scrollableDataTable issues with selecting rows
                          holstead

                           

                          "holstead" wrote:
                          HtmlScrollableDataTable.getKeys() doesn't exist.

                          Richfaces 3.1.1

                          What version should I be using?


                          Scratch this..obviously forgot to getSelection(). However, it is working. So for a scrollableDataTable you have to manually set the row key of the binding every time something is changed. Thank you.

                          • 10. Re: scrollableDataTable issues with selecting rows
                            ykravchenko

                            Hi holstead

                            Have You managed to make selection work right?

                            When I do table.getSelection().getKeys() an empty iterator i received even when some item is selected in table...

                            Could you give a clue how you have solved that

                            • 11. Re: scrollableDataTable issues with selecting rows
                              holstead

                               

                              "ykravchenko" wrote:
                              Hi holstead

                              Have You managed to make selection work right?

                              When I do table.getSelection().getKeys() an empty iterator i received even when some item is selected in table...

                              Could you give a clue how you have solved that


                              It may require the rowKeyVar attribute. Did you define it?

                              <rich:scrollableDataTable rowKeyVar="rkv" .....>

                              Here is the exact code I have working:

                              <h:commandButton value="<">
                               <a4j:support event="onclick" actionListener="#{NEPABean.linkThemeListener}" reRender="dt" />
                               </h:commandButton>
                              
                              <rich:scrollableDataTable id="sdt2" width="400" sortMode="single" rows="40" frozenColCount="1"
                               binding="#{NEPABean.unLinkedHtmlTable}" selection="#{NEPABean.unLinkedSelection}"
                               rowKeyVar="rkv" var="cur" value="#{NEPABean.unLinkedThemes}">
                               <rich:column id="c2" width="385">
                               <f:facet name="header">
                               <h:outputText value="UnLinked Resources"
                               style="font-weight: bold"/>
                               </f:facet>
                               <h:outputText value="#{cur.environment.name} - #{cur.name}" />
                               </rich:column>
                               <rich:column width="1" />
                               </rich:scrollableDataTable>
                              


                               public void linkThemeListener(ActionEvent evt) {
                               // get selected themes
                               Iterator keys = unLinkedHtmlTable.getSelection().getKeys();
                              
                               while(keys.hasNext()) { // working, iterates 3 times when 3 items selected
                               Object key = keys.next();
                               unLinkedHtmlTable.setRowKey(key);
                               .....
                               }
                               }
                              


                              • 12. Re: scrollableDataTable issues with selecting rows
                                ykravchenko

                                Actually I haven't tried to bind rowKeyVar. I'll give it a try, Could please tell me why selection="#{NEPABean.unLinkedSelection}" binding is needed nad does it actually occur?

                                • 13. Re: scrollableDataTable issues with selecting rows
                                  holstead

                                   

                                  "ykravchenko" wrote:
                                  ... Could please tell me why selection="#{NEPABean.unLinkedSelection}" binding is needed nad does it actually occur?


                                  For testing, I removed rowKeyVar and selection attributes. It seems to be behaving the same without them. I'll do further testing as I still have some bugs to try to figure out.

                                  • 14. Re: scrollableDataTable issues with selecting rows
                                    bdillon

                                    Hi,

                                    Did you manage to get the selection working with the ScrollableDataTable. I would be interested in knowing ho if you did as I had to do the following to work around it;

                                    add the following to the xhtml DataTable def;

                                    <a4j:support event="onselectionchange" actionListener="#{backingBean.selectedRowChanged}" />

                                    Then in your code have the following

                                    public void selectedRowChanged(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.currentSelectedRows = selected;
                                    }

                                    This is not ideal as the 'selection' attribute in the ScrollableDataTable should mean that this is not required.

                                    Thanks,

                                    Brian

                                    1 2 Previous Next