1 2 Previous Next 17 Replies Latest reply on Aug 31, 2011 8:54 AM by Manoj Nayak

    Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?

    John Bailo Master

      I want to connect a rich:dataTable to a bean that will manage serverside paging/scrolling for a large database.

       

      Currently I have a standard rich:dataTable with a rich:datascroller that loads all the records into a List inside a bean (but in dev I only use 100 records).

       

      My understanding is that this combination, out of the box, requires a complete dataload to the List.  
      The scroller then pages the data into the dataTable from the bean's List.

       

      However, I want the data to be selected (and filtered) from the database as needed, so only a few rows are pulled into the bean's List.

       

      Questions:

       

      1. Am I correct in assuming that I must write custom code to do this...that server/databaseside paging is not built-in to any RichFaces control?   I assume I will write my own filterMethod for my rich:column.

      2. Are there any existing data models for the bean that make this easier, or have the methods already written?

      3. Would it be easier to continue using the rich:datascroller, or as one article suggests, use my own scroll buttons to move data in and out of the bean and update the dataTable?

      4. For this application, would the dataTable, the extendedDataTable or the scrollableDataTable be the best choice?  I am not entirely sure that by "scrollable" they mean server side or just the same as using the datascroller control and paging through the bean's List dataset.
        • 1. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
          Ilya Shaikovsky Master
          1. Am I correct in assuming that I must write custom code to do this...that server/databaseside paging is not built-in to any RichFaces control?   I assume I will write my own filterMethod for my rich:column.

          2. Are there any existing data models for the bean that make this easier, or have the methods already written?

          1) yes you should implement ModifiableDataModel in order to control fetching on pagging with sorting and filtering considered.

          2) sample http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=modifiableDataModel&cid=13903, complete demo sources - jboss.org/richfaces/demos

           

          Would it be easier to continue using the rich:datascroller, or as one article suggests, use my own scroll buttons to move data in and out of the bean and update the dataTable?

           

          no, seems this sounds as some kind of workaround

           

          For this application, would the dataTable, the extendedDataTable or the scrollableDataTable be the best choice?  I am not entirely sure that by "scrollable" they mean server side or just the same as using thedatascroller control and paging through the bean's List dataset.

          The choise is simple - if you want to use dataScroller - use dataTable or extendedDataTable, you your requirements is to use vertical scrolling (datascroller will not works for that table ) - use scrollableTable.

          • 2. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
            John Bailo Master

            What is the form of the list vector that I can use to populate a DataVisitor for the walk() method?

             

            List list = new Vector();

            • 3. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
              Nick Belaevski Master

              John,

               

              DataVisitor deals with single data items, not a List of them. When component walks over list (for example), it notifies DataVisitor of each visited item. Data table components support walking over the same set of data types as standard h:dataTable (lists, arrays, Result, DataModel etc.) plus ExtendedDataModel. 

              • 4. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
                John Bailo Master

                I guess my question is more to the structure of the List.

                 

                Whereas in my standard DataTable implementation, I simply build a List of objects of my own definition, type User, in all the ExtendedDataModel examples that I could find, it seems that they create more elaborate Map or hash map structures (to create an artificial Primary Key) on top of the objects in the List.

                 

                I'm just trying to disambiguate the essentials of what is required from the examples, which seem to be showing off the features of the ExtendedDataModel.   I'm asking if I can simply use my list of type "User" objects, same as I've been doing with the standard DataTable, or if I now have to add them to a hashmap structure with the addition of a PK.

                • 5. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
                  Nick Belaevski Master

                  First of all, you can use List value with any RichFaces table and you don't need to wrap it into ExtendedDataModel.

                   

                  Maps in extended data models are necessary for values lookup by keys. Here is the typical usage sequence for ExtendedDataModel:

                   

                  1. Data model generates keys in walk(...) and passes them to DataVisitor
                  2. DataVisitor calls setRowKey() on the model and passes row key back
                  3. Model client calls getRowData(), model takes current key, looks item value in map and returns it.

                   

                  For Hibernate-based models this map can be eliminated and entities taken directly from session; also the same approach as on livedemo can be used: http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=modifiableDataModel&cid=115604 . There entities are used as row keys, and rowKeyConverter (Seam entity converter is used) defined in the page code is doing actual conversion of entities.

                  • 6. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
                    John Bailo Master

                    I can't use Hibernate in this instance because my JNDI source is an ADAM server.

                     

                    For the Primary Key, do I have to use an Integer?

                     

                    The key in my case is a uid, which is a String.

                     

                    Can I use String as my pK?

                     

                    Right now I'm doing that, but for some reason, although I've set rows="10" on the rich:dataTable it's displaying all 100 rows of sample data (which I've hard coded for testing purposes).   The rich:datascroller works, but it always shows the complete 100 rows, rather than scrolling through the sample data 10 rows at a time.    Is that due to having a non-Integer value as the pK ?

                    • 7. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
                      Nick Belaevski Master

                      >> For the Primary Key, do I have to use an Integer?

                       

                      No, any serializable value should work. Some row key types can require rowKeyConverter to be set (that is for the case when JSF doesn't support conversion by type; for numeric types it's not necessary normally).

                       

                      >> Can I use String as my pK?

                       

                      Yes.

                       

                      >> Right now I'm doing that, but for some reason, although I've set rows="10" on the rich:dataTable it's displaying all 100 rows of sample data

                      >> (which I've hard coded for testing purposes).   The rich:datascroller works, but it always shows the complete 100 rows, rather than

                      >> scrolling through the sample data 10 rows at a time.    Is that due to having a non-Integer value as the pK ?

                       

                      No, PK should not affect this. Can happen if your model ignores "rows" attribute passed in Range object - please check what value is there.

                      • 8. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
                        John Bailo Master

                        I've advanced a little bit.

                         

                        I found in debug that the MaxListSize was being read before being set.   I hardcoded a value:

                         

                        public int getMaxListSize(){return 100;}

                         

                        And now the dataScroller lets me page.   However, the current behavior is...given a dataTable of 10 rows, the first page displays fine.  If I click page 2, the code runs, the range goes from 0,10 to 10,10 as it should, and new records are read (in this case, I simulate that with a for loop that just adds 10 records with the key a+1 to the list).

                         

                        for(int i=startRow; i < size; i++)
                          list.add(new User("a"+i, "b", "c", "d", "e"));

                        But page 2 (and all other pages) are blank!   If I scroll back to page 1, the first set of data, a0 - a9, are there.
                        This is my jsf page:
                        <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%> 
                        <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%> 
                        <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> 
                        <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> 
                        <a4j:keepAlive beanName="userBean2"/>
                        <html> 
                          <head>
                           <title>RichFaces</title>
                           <style type="text/css">  
                           .row1 { 
                             background-color: #EDEBEB; 
                             font-size: 10px; 
                        .row2 { 
                             background-color: #ffffff; 
                             font-size: 10px; 
                          
                        </style>
                          </head>
                          <body>
                           <f:view>
                           <h:form>
                        <h:panelGrid id="exampleContainer" columns="1" >
                        <rich:dataTable
                        id="exampleListDT"
                        value="#{exampleListModel.exampleList}"
                        var="user"
                        rows="10"
                        style="width:100%" rowKeyVar="row">
                        <h:column>
                        <f:facet name="header">
                        <h:outputText value="Column1" />
                        </f:facet>
                        <h:outputText value="#{user.name}" />
                        </h:column>
                        <f:facet name="footer">

                        <rich:datascroller
                        align="left"
                        for="exampleListDT"
                        ajaxSingle="false" />

                        </f:facet>
                        </rich:dataTable>
                        <rich:spacer height="5" />
                        </h:panelGrid>
                        </h:form>
                           </f:view>
                          </body>
                        </html>
                        • 9. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
                          John Bailo Master

                          Nick Belaevski wrote:

                           

                          >> For the Primary Key, do I have to use an Integer?

                          No, any serializable value should work. Some row key types can require rowKeyConverter to be set (that is for the case when JSF doesn't support conversion by type; for numeric types it's not necessary normally).

                           

                          >> Can I use String as my pK?

                          Yes

                           

                          So, what I did is went back to square one to see if I could get this to work at all.  I found a simpler and more recent implementation here:

                           

                          http://gochev.blogspot.com/2009/08/richfaces-server-side-paging-with.html

                           

                          I loaded this project and it worked from the get go...however, he is using an Integer as the pK.   (Up above in this thead, I took some more elaborate code and converted to using a String as my pK.)

                           

                          After getting the new project to work, I converted the datatype for the pK and List/Array indexes to String.

                           

                          I got the same behavior -- Page 1 displayed fine, but all other pages displayed blank.  In the debugger, I saw that the wrappedKeys were being updated with the proper data.

                           

                          I then attempted to implement rowKeyConverter in my dataTable, but I could not find adequate examples or documention.   What exactly am I supposed to use to convert uid ( jbailo, for example ) to a numerical index ?

                           

                          It seems to me that if my pK is String, and dataTable wants a number, I don't see how it could ever be accomdated!

                           

                          A better solution seems to be as above, where he adds an Integer key to the User object for the sake of indexxing the dataTable.

                          • 10. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
                            Nick Belaevski Master

                            John,

                             

                            All iteration components in RF are inherited from base class extending capabilities of UIData (base class for standard JSF iteration components). Extension is that these components work not only with indices but with any arbitrary key. Limitations of this key are the following:

                             

                            1) It is serializable

                            2) Being converted to string, it should conform to HTML ID format

                             

                            While point #1 is simple and 99.9% cases is true, point #2 is the thing that may require additional conversion functionality wired via rowKeyConverter attribute. Typical usage:

                             

                            1) Composite entity key

                            2) Using entity itself as key in model (that's what livedemo shows)

                            3) Keys that do not conform to HTML ID format being converted via toString() (e.g. strings containing national alphabet symbols)

                             

                            As far as I understand, you are using GUID as entity id, so it should be conformant to HTML ID format. To check that, please add <a4j:log popup="false" /> to the page and check if there are any errors/warnings there and whether AJAX response shows data for new page or not. Please post results of your check here. Also can you please post complete model/page code for investigation?

                             

                            It seems to me that if my pK is String, and dataTable wants a number, I don't see how it could ever be accomdated!

                            Seam framework provides entity converter that stores entities in page-scoped (IIRC) storage by sequential indices thus making conversion easy.

                            • 11. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
                              John Bailo Master

                              Well I finally got this working with a large dataset, server side pagination and the dataScroller (and it works great!!)

                               

                              Now, I want to implement filter and sort for my dataTable.

                               

                              I tried just adding in a sortBy= attribute to one of my columns.to see what would happen, and at that point, the dataScroller showed zero records.

                               

                              In doing the research it appears that when using the ExtendedDataModel I have to implement my own server-side filter and sort methods, however, some articles say that I even have to implement my own controls on using commandLinks and actionParams.  For example:

                               

                              http://eclecticprogrammer.com/2008/06/25/sorting-and-paginating-in-the-database-with-richfaces/

                               

                              Based on the Richfaces 3.3 components, can someone clarify exactly what work I have to do to implement serverside filtering and sorting when using the ExtendedDataModel?

                               

                              Can I simply use the sortBy= attribute and have it trigger an overrided method on the backing bean?

                               

                              Or do I have to implement my own UI sort controls and use a backing bean for those controls?

                               

                              This demo for external tablesorting seems to suggest that, but the backing bean code is not provided:

                               

                              http://livedemo.exadel.com/richfaces-demo/richfaces/sortingFeature.jsf?c=sorting&tab=ex-usage

                              • 13. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
                                Moha Mans Newbie

                                Hi John,

                                John Bailo schrieb:

                                 

                                Well I finally got this working with a large dataset, server side pagination and the dataScroller (and it works great!!)

                                I am facing the same problem, can you please post your solution? It would be helpful for many developers!

                                First of all, I am using JSF 2 with Richfaces 4.0 (beta).

                                I have extended the SerializableDataModel with dataProvider that has a Spring service bean to get data.

                                 

                                When I debug the walk method, wrappedData map is filled correctly according to the range, but:

                                1- The dataScroller although showing the right number of pages, it has a strange behavior, when hitting the navi forward buttons as well as the numbers, I can see the changes on the scroller highlight and activate-deactivate functionality. Secondly, hitting the numbers backwardly, the same happens except for the First Page (#1). Moreover, the navi backward buttons despite they are activated when mocing forward, they are not working (going to the back page numbers).

                                 

                                2- The First page data is shown correctly at the beginning before using the dataScroller, but whatever I clicked on the dataScroller, the same table contents stay and do not change and do not disapear.

                                 

                                I have used Nick's advice (<a4j:log popup="false" />) and the Ajax response seems to be ok (as contents) but I got the error:

                                return 'error@malformedXML' on <span ...>

                                 

                                I have treid to find what causes this stuff and no way! and for two days still fighting to make the whole stuff working!

                                Please help solving and saving my Christmas!

                                 

                                Appreciate any help!

                                • 14. Re: Scrolling Large Data Sets: What Is The Best Choice; dataTable, extendedDataTable, scrollableDataTable?
                                  John Bailo Master

                                  Moha,

                                   

                                  I was able to get mine to work using the extendedDataTable and extendedDataModel.

                                   

                                  I had to use a custom data model, custom walk() method and custom handlers for filter, and so on because I had the same problem as you...the paginator would not fire off properly.

                                   

                                  I highly suggest you read this article about using an extendedDataModel and you can download his source here as a starter:

                                   

                                  http://gochev.blogspot.com/2009/08/richfaces-server-side-paging-with.html

                                   

                                  (Sorry I took so long to reply...this web site has been crashing my Firefox on my netbook.  IE too.  Finally went with Chrome!)

                                  1 2 Previous Next