12 Replies Latest reply on May 6, 2009 3:18 PM by Chris Lambert

    SimpleSelection with ExtendedDatTable

    Todd Gould Novice

      Hello,

      I'm having difficulties getting the correct results from the combination of the SimpleSelection when used with the ExtendedDataTable. I get the correct results as long as the table has NOT been sorted by any columns (i.e. original order). However, as soon as I sort the table by a column, the results produced are incorrect (single sortMode).

      The only examples I have found seem to be used with a ScrollableDataTable. These examples show that the getSelection().getKeys() method returns Iterator. Yet in the case of the ExtendedDataTable, it just returns and Iterator - which is effectively just Integers.

      I also thought of calculating the the correct index based on the SortOrder; but, even though I am monitoring the SortOrder, the SortOrder.getFields() method always returns null.


      Here is my table definition....

      
       <rich:extendedDataTable id="discoveryListTable"
       value="#{discoveryLists}" var="discoveryList"
       eventsQueue="discoveryListEvents"
       onRowMouseOver="this.style.backgroundColor='#FFFFCC'"
       onRowMouseOut="this.style.backgroundColor='#{a4jSkin.rowBackgroundColor}'"
       rowClasses="lightRow, lightRow, lightRow, darkRow, darkRow, darkRow"
       selectedClass="selectedRow"
       height="370px" width="100%"
       rows="15"
       sortMode="single"
       sortOrder="#{discoveryListController.sortOrder}"
       tableState="#{discoveryListController.tableState}"
       selectionMode="multi"
       selection="#{discoveryListController.selection}"
       status="mainStatus">
      
       <a4j:support event="onselectionchange"
       ajaxSingle="true" action="#{discoveryListController.onSelectionChange()}"
       reRender="clearSelectionButton,editButton,deleteButton,discoveryListMsgs"
       limitToList="true"/>
      
      .....
      </rich:discoveryList>
      


      Finally, and most importantly, due to some complexities with the way Seam conversations are used in this application, I CANNOT make use of the RichFaces ExtendedDataTable binding attribute to gain access to the table and consequently 'determine' the correct row via a getTable().setRowKey( key ) style operation.

      Finally, I have also tried to use the Seam @DataModelSelection without success. Unfortunately, it always returns the last value in the List - regardless of sort order of table. I had thought this would work, but apparently not, or I'm missing something else?

       @DataModel
       protected ArrayList<DiscoveryList> discoveryLists = null;
      
       @DataModelSelection
       @In( required=false )
       @Out( required=false )
       protected DiscoveryList selectedDiscoveryList = null;
      
      
      


      Furthermore, this mechanism seems to be incomplete in a multiple selection table? It would seem that you would need to 'build-up' a list of multiple selections as the user makes them?

      I'm really at a loss. If I could use the binding attribute, I can make things work properly. However, as the app uses multiple ExtendedDataTables within a conversation, this is not possible - binding will cause columns and other table info to 'cross-pollinate' between the tables when using the EVENT scope controller required for binding attributes in a Seam application.

      The SimpleSelection method appears to be the only approach left/best approach in this environment. However, it does not produce the correct results when the table is sorted?

      Can anyone help me out with some insight, ideas or point me to some ExtendedDataTable specific examples WITHOUT binding for tracking and accessing multi selection in a backing bean component?

      Thank you!

        • 1. Re: SimpleSelection with ExtendedDatTable
          Chris Lambert Newbie

          I have the same problem, seems to binding rich components with the seam components doesn't work at all, or maybe I do something wrong?
          Did someone try suggestion form seam reference with success ?:

          To work around this use an event scoped component to store the component bindings and inject
          it into the conversation scoped component that requires it.



          my binding bean:
          @Name("extable")
          @Scope(EVENT)
          public class ExTable {
          
           private UIExtendedDataTable exTable ;
          
           public UIExtendedDataTable getExTable() {
           return exTable;
           }
          
           public void setExTable(UIExtendedDataTable exTable) {
           this.exTable = exTable;
           }
          
          }


          and error
          javax.el.ELException: /test.xhtml @51,163 binding="#{extable.exTable}": java.lang.IllegalArgumentException: argument type mismatch




          • 2. Re: SimpleSelection inccorect results with ExtendedDataTable
            Todd Gould Novice

            Coalos,

            Yes binding works just fine for me. But this is NOT what this Topic is about. In hopes it will help you, here is my Event based component.


            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.PerNestedConversation;
            import org.jboss.seam.annotations.Scope;
            import org.jboss.seam.annotations.Logger;
            import org.jboss.seam.log.Log;
            
            import org.richfaces.component.UIExtendedDataTable;
            
            @Scope( ScopeType.EVENT )
            @Name( "extendedDataTableController" )
            public class ExtendedDataTableControllerBean
             implements IExtendedDataTableController
            {
             protected UIExtendedDataTable table_;
            
             @Logger
             protected Log log;
            
             /* (non-Javadoc)
             * @see com.ensuren.sms.apps.common.controllers.IExtendedDataTableController#getTable()
             */
             public UIExtendedDataTable getTable()
             {
             log.trace( "getTable returns " + table_ );
             return table_;
             }
            
             /* (non-Javadoc)
             * @see com.ensuren.sms.apps.common.controllers.IExtendedDataTableController#setTable(org.richfaces.component.UIExtendedDataTable)
             */
             public void setTable( UIExtendedDataTable table )
             {
             log.trace( "setTable has " + table );
             this.table_ = table;
             }
            }
            


            The Facelet that references it has:

             <rich:extendedDataTable id="discoveryListTable"
             value="#{discoveryLists}" var="discoveryList"
             eventsQueue="discoveryListEvents"
             onRowMouseOver="this.style.backgroundColor='#FFFFCC'"
             onRowMouseOut="this.style.backgroundColor='#{a4jSkin.rowBackgroundColor}'"
             rowClasses="lightRow, lightRow, lightRow, darkRow, darkRow, darkRow"
             selectedClass="selectedRow"
             height="370px" width="100%"
             rows="15"
             sortMode="single"
             sortOrder="#{discoveryListController.sortOrder}"
             tableState="#{discoveryListController.tableState}"
             selectionMode="multi"
             selection="#{discoveryListController.selection}"
             binding="#{extendedDataTableController.table}"
             status="mainStatus">
            


            Binding does work in this fashion with the Event scoped component. However, this will not work for me as the binding to an Event scoped component causes cross-pollination of table columns to the multiple extendedDataTables I have in the UI.

            I can avoid binding altogether (and hence solve my problem) if I can figure out how to get the correct results from the SimpleSelection ( selection="#{discoveryListController.selection}" ) even when the columns have been sorted.

            Is this a known bug? More likely, I am missing something simple and I would greatly appreciate any and all help on this issue/topic - Ho to get correct results from SimpleSelection when used with ExtedendedDataTable following column sort???

            Thanks again in advance.

            • 3. Re: SimpleSelection with ExtendedDatTable
              Nick Belaevski Master

              Hello,

              Please take a look:

              private UIDataAdaptor findUIDataAdaptor(UIComponent component) {
               UIComponent result = component;
               while (result != null) {
               if (result instanceof UIDataAdaptor) {
               return (UIDataAdaptor) result;
               } else {
               result = result.getParent();
               }
               }
              
               return null;
               }
              
               private List<Object> convertSelection(UIDataAdaptor dataAdaptor) {
               List<Object> result = new ArrayList<Object>();
              
               FacesContext facesContext = FacesContext.getCurrentInstance();
               Object rowKey = dataAdaptor.getRowKey();
              
               try {
               if (selection != null) {
               SimpleSelection simpleSelection = (SimpleSelection) selection;
               for (Iterator<Object> keys = simpleSelection.getKeys(); keys.hasNext();) {
               Object nextKey = keys.next();
              
               dataAdaptor.setRowKey(facesContext, nextKey);
               result.add(dataAdaptor.getRowData());
               }
               }
               } finally {
               try {
               dataAdaptor.setRowKey(facesContext, rowKey);
               } catch (Exception e) {
               facesContext.getExternalContext().log(e.getMessage(), e);
               }
               }
              
               return result;
               }
              
               public void printSelection(ActionEvent actionEvent) {
               List<Object> convertedSelection = convertSelection(findUIDataAdaptor(actionEvent.getComponent()));
              
               System.out.println(convertedSelection);
               }


              <rich:extendedDataTable value="#{forum5Bean.lotOfData}" var="item"
              
               sortMode="single"
               selectionMode="multi"
               selection="#{forum5Bean.selection}"
               >
               <rich:column sortBy="#{item}">
               <f:facet name="header">text</f:facet>
               <h:outputText value="#{item}" />
               </rich:column>
              
               <a4j:support event="onselectionchange"
               ajaxSingle="true" actionListener="#{forum5Bean.printSelection}"
               limitToList="true"/>
              
               </rich:extendedDataTable>



              • 4. Re: SimpleSelection with ExtendedDatTable
                Todd Gould Novice

                nbelaevski,

                Thank you very much! I have plugged this in and, following a quick test, it appears to be working perfectly! I'll need to do some more through tests when I return later in the week, but I think this looks most promising given then constraints of my environment (i.e. no binding).

                The UIDataAdapter is new to me? I could not find it referenced in the RF Developer's Guide? Can you point me to some info on it, so that I can become better informed?

                Thank again!

                • 5. Re: SimpleSelection with ExtendedDatTable
                  Nick Belaevski Master

                  org.ajax4jsf.component.UIDataAdaptor class is a parent class for all iteration components in RF; it extends standard JSF UIData with the notion of row keys that have the same meaning as row indexes, but can be complex objects. Also UIDataAdaptor supports partial AJAX rows re-rendering.

                  • 6. Re: SimpleSelection with ExtendedDatTable
                    Chris Lambert Newbie

                     

                    "nbelaevski" wrote:
                    org.ajax4jsf.component.UIDataAdaptor class is a parent class for all iteration components in RF; it extends standard JSF UIData with the notion of row keys that have the same meaning as row indexes, but can be complex objects. Also UIDataAdaptor supports partial AJAX rows re-rendering.


                    Hi

                    What do You think, what can be wrong if function
                    UIDataAdaptor findUIDataAdaptor(UIComponent component) doesn't find class UIDataAdaptor? , works with UIData only

                    private UIDataAdaptor findUIDataAdaptor(UIComponent component) {
                    
                     System.out.println("FIND ADAPTOR Started");
                     UIComponent result = component;
                     while (result != null) {
                     if (result instanceof UIDataAdaptor) {
                     //if (result.getFamily()=="org.richfaces.ExtendedDataTable"){
                     System.out.println(" ADAPTOR FOUND "+result.getClass());
                    
                     return (UIDataAdaptor) result;
                    
                     } else {
                     result = result.getParent();
                     if (result != null) System.out.println("FIND ADAPTOR SCAN "+result.getClass());
                     }
                    
                    
                     }
                    
                     return null;
                     }
                    
                    

                    outcome code :
                    [url=http://img294.imageshack.us/my.php?image=clipboard02xpt.jpg]
                    [img]http://img294.imageshack.us/img294/7509/clipboard02xpt.th.jpg[/img][/url]

                    I'm using richfaces-3.3.0.GA with Seam 2.1.2.CR1



                    • 7. Re: SimpleSelection with ExtendedDatTable
                      Nick Belaevski Master

                      Can happen if RF is not in classpath.

                      • 8. Re: SimpleSelection with ExtendedDatTable
                        Todd Gould Novice

                        Coalas,

                        Given the "java.lang.IllegalArgumentException: argument type mismatch" error you mentioned in your earlier post, I'm wondering if you may not have multiple ClassLoaders referencing the same (or differing) versions of the class. Take a look at the structure of your war/ear with a close look at what's being loaded from where. I suspect classloading may be at the root of your troubles if your source code appears to be in harmony with the snippets I previously posted.

                        Bet of luck!

                        • 9. Re: SimpleSelection with ExtendedDatTable
                          Todd Gould Novice

                          Ok, switching to the UIDataAdaptor seems to working in terms of tracking the selection to a backing component and without binding. However, this approach appears to create some difference in the ExtendedDataTable's mangement of 'selected' rows when rows are deleted/edited. Is there a method to either get at the ExtendedDataTable and/or control the selection emphasis on the UI side for specific rows via the UIDataAdaptor (or other means) - without binding, of course.

                          Thanks.

                          • 10. Re: SimpleSelection with ExtendedDatTable
                            Nick Belaevski Master

                            UIExtendedDataTable either implements UIDataAdaptor. You can cast found UIDataAdaptor to UIExtendedDataTable if you need special treatment.

                            • 11. Re: SimpleSelection with ExtendedDatTable
                              Chris Lambert Newbie

                               

                              "skidvd" wrote:
                              Coalas,

                              Given the "java.lang.IllegalArgumentException: argument type mismatch" error you mentioned in your earlier post, I'm wondering if you may not have multiple ClassLoaders referencing the same (or differing) versions of the class. Take a look at the structure of your war/ear with a close look at what's being loaded from where. I suspect classloading may be at the root of your troubles if your source code appears to be in harmony with the snippets I previously posted.
                              Bet of luck!


                              Hi skidvd
                              If you have a while, please take a look at this post
                              http://www.seamframework.org/Community/JavalangNoClassDefFoundErrororgrichfacescomponenthtmlHtmlInplaceSelect
                              I think I have exactly the same problem. I can't run application unless I copy richfaces's libs to ear/lib directory, but this is not good solution in this case.
                              You never observed something like this? What is your solution for this issue, that is works for you?
                              Sorry for this small mess in your topic, maybe I give you my mail:
                              coalas.bladeforums@gmail.com
                              regards Chris

                              • 12. Re: SimpleSelection with ExtendedDatTable
                                Chris Lambert Newbie

                                 

                                "Coalas" wrote:
                                "skidvd" wrote:
                                Coalas,

                                Given the "java.lang.IllegalArgumentException: argument type mismatch" error you mentioned in your earlier post, I'm wondering if you may not have multiple ClassLoaders referencing the same (or differing) versions of the class. Take a look at the structure of your war/ear with a close look at what's being loaded from where. I suspect classloading may be at the root of your troubles if your source code appears to be in harmony with the snippets I previously posted.
                                Bet of luck!


                                Hi skidvd
                                If you have a while, please take a look at this post
                                http://www.seamframework.org/Community/JavalangNoClassDefFoundErrororgrichfacescomponenthtmlHtmlInplaceSelect
                                I think I have exactly the same problem. I can't run application unless I copy richfaces's libs to ear/lib directory, but this is not good solution in this case.
                                You never observed something like this? What is your solution for this issue, that is works for you?
                                Sorry for this small mess in your topic, maybe I give you my mail:
                                coalas.bladeforums@gmail.com
                                regards Chris


                                I put bean's for richfaces in web-inf class folder and it's seems to be ok... I did it before I wrote earlier post, but I did not check this sufficiently closely .. I guess..
                                Thanks for your advice :)