9 Replies Latest reply on Mar 9, 2010 1:57 AM by Eugene Bessel

    [3.3.0.BETA5] Pagination & Sorting with ExtendedTableDataMod

    Gerrit Brehmer Newbie

      Hi,

      I'm using ExtendedTableDataModel (for rich:dataTable) with own Implementation of DataProvider Interface to get data from database and own Implementation of Modifiable Interface to generate special sort/order requests (Setting additional values from DataProviderImpl).

      Pagination functions properly, but I have some problems with too many db requests and with sorting feature:

      How can I prevent data range/count requests during decode, validation & update phase? I see that the Implementation from ExtendedTableDataModel was changed (removed SerializableDataModel in early 3.3.0)

      And because the first request to the database is before setting the new sorting/order value from column, the request to the database always use the value from the previous request.

      Can you provide any example implementation? I found some old examples, but they always don't use ExtendedTableDataModel and I thought that this will be your base class for real db pagination support (+ DataProvider).

        • 1. Re: [3.3.0.BETA5] Pagination & Sorting with ExtendedTableDat
          Gerrit Brehmer Newbie

          if I call "reset" from ExtendedTableDataModel after each "modify", the right sort values will be used but it generates 4-5 count requests and 1-2 range during page lifecycle if sorting is enabled.

          • 2. Extending ExtendedTableDataModifiableModel
            Gerrit Brehmer Newbie

            Next try:

            I switched to "ExtendedTableDataModifiableModel". This class helps me to find the right time to request new sorted data from db.
            But this class doesn't use the dataProvider and so I must replace walk and rowCount method.

            But now I would like to use the rich:dataTable instead of rich:extendedDataTable, because I don't want scrolling or extra column menus. Could you provide tag options for that to disable these functionalities?

            Could you give an example? Should I raise a Jira issue for that (Giving an real world example for paging and sorting directly with db)? Should I contact the developer directly (Pawel Golawski)?

            My version of TableData:

            /**
             * DaoTableData (request scope)
             */
            public class DaoTableData<T> extends ExtendedTableDataModifiableModel<T> {
            
             /**
             * serial version id
             */
             private static final long serialVersionUID = 8711344721077597569L;
            
             /**
             * session scope data provider
             */
             private final DataProvider<T> dataProvider;
            
             private Integer lastRowCount;
            
             public DaoTableData(final DataProvider<T> dataProvider) {
             super(dataProvider);
             this.dataProvider = dataProvider;
             }
            
             @Override
             public void modify(final List<FilterField> filterFields, final List<SortField2> sortFields) {
            
             // change order
             ((ExtendedDataProvider<T>) this.dataProvider).setOrder(sortFields.get(0).getOrdering());
            
             // change sort expression -> sort column
             String sortExp = sortFields.get(0).getExpression().getExpressionString();
             sortExp = sortExp.substring(sortExp.indexOf('.') + 1, sortExp.indexOf('}'));
             ((ExtendedDataProvider<T>) this.dataProvider).setColumn(sortExp);
            
             // reset values -> count & page must be newly requested
             reset();
             }
            
             @Override
             public int getRowCount() {
             if (this.lastRowCount == null) {
             // reset last session scope data provider row count
             ((ExtendedDataProvider<T>) this.dataProvider).setLastRowCount(null);
            
             // get latest row count from db
             this.lastRowCount = Integer.valueOf(this.originalModel.getRowCount());
            
             // set data provider row count to not using database directly for that during request
             ((ExtendedDataProvider<T>) this.dataProvider).setLastRowCount(this.lastRowCount);
             }
             return this.lastRowCount.intValue();
             }
            
             @Override
             public void walk(final FacesContext context, final DataVisitor visitor, final Range range,
             final Object argument) throws IOException {
             this.originalModel.walk(context, visitor, range, argument);
             }
            
             @Override
             public void resetSort() {
             ((ExtendedDataProvider<T>) this.dataProvider).setSortNeeded(true);
             super.resetSort();
             }
            
            }
            


            • 3. Re: Extending ExtendedTableDataModifiableModel
              Andrew Zakovorotny Newbie

              Hi Gerrit,

               

              Did you get any reply on your request regarding using rich:dataTable with ExtendedTableDataModifiableModel?

              I've installed RichFaces 3.3.1 and now am trying to solve the same problem you had.

               

              Thank you.

              Andy.

              • 4. Re: Extending ExtendedTableDataModifiableModel
                Nick Belaevski Master

                Hi Andy,

                 

                I'd suggest you to take look at this demo: http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=modifiableDataModel&cid=106857. It uses custom model and shows how to build Hibernate Query according to rich:dataTable's sorting/filtering/paging.  

                • 5. Re: Extending ExtendedTableDataModifiableModel
                  Andrew Zakovorotny Newbie

                  Thanks for the reply, Nick.

                  Unfortunately I could not find richfaces-demo sources. Examples bundled with 3.3.2.SR1 do not contain relevant code.

                  I was hoping to get some insight on how to use/extend one of the provided data models that could be used with rich:dataTable to perform true paging/sorting with minimal additional coding. I could probably come up with my own solution (based on Inet materials) however, tight project schedule makes it quite difficult to manage.

                  Is the source for that demo is available for public?

                   

                  Thanks again.

                  Andy.

                  • 6. Re: Extending ExtendedTableDataModifiableModel
                    Andrew Zakovorotny Newbie

                    Nick, please disregard my message. I found demo sources.

                     

                    Sorry for bothering you.

                     

                    Andy.

                    • 7. Re: Extending ExtendedTableDataModifiableModel
                      Andrea Bolognesi Newbie

                      Dear Nick,

                      I've found the demo at http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=modifiableDataModel&cid=106857 extremely usefull.

                       

                      For whom is interested in adapting it to handle large tables here are some hints. I just modified few lines in BaseModifiableHibernateDataModel:

                      1)  in getRowCount() I used a projection instead of simply counting the size of the whole retrieved list. These lines

                      {code}

                                criteria.setProjection(Projections.rowCount());
                                return ((Integer)criteria.list().get(0)).intValue();

                      {code}

                           instead of

                      {code}

                                return (Integer) criteria.list().size();

                      {code}

                       

                      2)  in appendSorts method i modified

                      {code}criteria.addOrder(order.ignoreCase());{code}

                           into

                      {code}criteria.addOrder(order);{code}

                           in order to use table indexes

                       

                      Anyway, thanks for the great demo!

                      A.

                      • 8. Re: Extending ExtendedTableDataModifiableModel
                        Nick Belaevski Master

                        Andrea,

                         

                        Thank you for suggestions! I've created a task to apply them to demo code: https://jira.jboss.org/jira/browse/RF-8327

                        • 9. Re: Extending ExtendedTableDataModifiableModel
                          Eugene Bessel Newbie

                          Hi Gerrit,

                           

                          you added a part of you code of DataModel.

                           

                          how have you implemented it in xhtml.

                          I have the following problem:

                           

                          public void modify(List<FilterField> arg0, List<SortField2> sortFields) {
                                   if (!sortFields.isEmpty()) {
                                         final SortField2 sortFild = sortFields.get(0);
                                         final Expression expression = sortFild.getExpression();
                                         final String expressionString = expression.getExpressionString();
                                         ordering = sortFild.getOrdering();
                                         sortFieldName = getExpressionName(expressionString);
                                        }
                                   System.out.println("");
                              }

                          XHTML:

                           

                          <rich:columns id="col_#{col}" value="#{userbbean.columns}"
                                      selfSorted="true" sortBy="#{data[ind]}" sortOrder="#{myDataTable.sortOrders[col]}"
                                       var="col" index="ind">

                           

                          When the appliation go into modify I have always sortFieldName = "#{data[ind]"

                          what I have done wrong??

                          Maybe I can not use modify method with columns Tag??

                           

                          thank you for your Answer.

                           

                          wbr

                          Eugene