13 Replies Latest reply on Jan 4, 2011 5:40 AM by ilya_shaikovsky

    pagination and lazy data loding

    ilya40umov

      Hellow Folks,
      I have been asking myself a lot of times about this question. Actually I've come for some solution three times and I don't fully like none of them.
      My last solution has been based on ExtendedDataModel and it's very similar to the solution from the following URL:
      But I still don't like some parts of this solution with sorting and filtering. Because JSF acts very odd and the DataModel sometimes executes the same sql queries twice per request.
      I wonder if there is some similar solution published on Richfaces forum. And I also very want to know the answer for the next question. Are you going to add a similar solution to RF 4.0 or may be to RF 4.0 usage examples? It could help a lot if you simply add some solution based on DataModel class into RF live demo. I even can help a little bit and write an article about this topic if you don't have it already. =) Because I think this stuff is very usefull in development of an enterprise application.
      I appreciate any answers,
      Thanks for your attention!

      Hellow Folks,

      I have been asking myself a lot of times about this question. Actually I've come for some solution three times and I don't fully like none of them.

      My last solution has been based on ExtendedDataModel and it's very similar to the solution from the following URL:

      http://seamframework.org/Community/TroublesToUseDatascrollerAndExtendedDataModel

      But I still don't like some parts of this solution with sorting and filtering. Because JSF acts very odd and the DataModel sometimes executes the same sql queries twice per request.

      I wonder if there is some similar solution published on Richfaces forum. And I also very want to know the answer for the next question. Are you going to add a similar solution to RF 4.0 or may be to RF 4.0 usage examples? It could help a lot if you simply add some solution based on DataModel class into RF live demo. I even can help a little bit and write an article about this topic if you don't have it already. =) Because I think this stuff is very usefull in development of an enterprise application.

      I appreciate any answers,

      Thanks for your attention!

        • 1. Re: pagination and lazy data loding
          ilya40umov

          I've found discussions about this topic on RF forum. There is one of them http://community.jboss.org/thread/153022. So I geuss my the question simply is this. Do you have official article about using DataModel with filtering & sorting? And are you going to include something in this topic into RF 4.0 show case application?

          Best Regards,

          Ilya.

          • 2. Re: pagination and lazy data loding
            ilya_shaikovsky
            Do you have official article about using DataModel with filtering & sorting?

            article - no, sample - yes http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=modifiableDataModel&cid=843854

             

            And are you going to include something in this topic into RF 4.0 show case application?

            definitelly yes.. just need some more time

            • 3. Re: pagination and lazy data loding
              ilya40umov

              Thank's for the answer. This link is helpful and I will appreciate if RF 4.0 show case would contain a similar sample too. But I already tried ExtendedDataModel and Modifiable interface once with jsf 1.2 and RF 3.3.3. I found that they call the same SQLs during one request so I've written my own implementations(I also don't like filters in headers but this is personal). I'm gonna try it again with RF 4.0.

              • 4. Re: pagination and lazy data loding
                ilya40umov

                Finally I download code of BaseModifiableHibernateDataModel and tried it but with a few changes(I don't like such kind of filtering and I don't want to allow hibernate to create queries dinamically.) I found that dataModel calls getRowCount() 2-3 times per request so I had to add the following code:

                 

                private final String dataModelID = UUID.randomUUID().toString();

                private Integer rowCount;

                 

                 

                @Override

                    public int getRowCount() {

                        Map<String, Object> map = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();

                        if (rowCount == null || map.get(dataModelID + "_asked") == null) {

                            rowCount = new Integer(findRowCount());

                            map.put(dataModelID + "_asked", "");

                        }

                        return rowCount.intValue();

                    }

                 

                P.S. I used JSF 2.0 and RF 3.3.3 with GlassFish 3.0.1

                @Override
                    public int getRowCount() {
                        Map<String, Object> map = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
                        if (rowCount == null || map.get(dataModelID + "_asked") == null) {
                            rowCount = new Integer(findRowCount());
                            map.put(dataModelID + "_asked", "");
                        }
                        return rowCount.intValue();
                    }
                • 5. Re: pagination and lazy data loding
                  nbelaevski

                  Ilya,

                   

                  Be aware that such type of caching will work wrong if user changes model dynamically (e.g. switches to another data source in some action method).

                  • 6. Re: pagination and lazy data loding
                    ilya40umov

                    Thank you for your reply.

                    And yes, I understand that sometimes my approach could be wrong(Actually I hardy could imagine the situation you described) but anyway performing the same SQL query a couple of time looks like very odd(Of course some DBs can cash query results very well but I used to optimize my code when it's possible and don't hope on luck).

                    • 7. Re: pagination and lazy data loding
                      nbelaevski

                      Well, the simplest example: insertion/deletion of item. Cached model will still show stale data & row count if no special measures are taken.

                      • 8. Re: pagination and lazy data loding
                        ilya40umov

                        May be you misunderstood my solution. My workaround only forces dataModel to call "select COUNT(*) from ..." only once per request. So the count of entries should be calculated again during every request. Do you mean that count may also be changed during a request?

                        • 9. Re: pagination and lazy data loding
                          nbelaevski

                          Yes, during request. User deletes/inserts item from the table by action.

                           

                          BTW, Seam runs two transactions - one for 'execute', another for 'render' parts of lifecycle.

                          • 10. Re: pagination and lazy data loding
                            ilya40umov

                            I don't use Seam but my app also executes 'insert/delete/update' and 'render' in two different transactions. And I'm sure that my "insert/delete/update" is to be executed before "render" of page so that items count should be calculated after transaction has been completed. And I didn't have any problems with it. But I don't know about Seam of course.

                            • 11. Re: pagination and lazy data loding
                              ilya40umov

                              Hi guys!

                              I tried to migrate this stuff to RF 4.0 M4 and found that the following classes are missing:

                              import org.richfaces.model.Modifiable;

                              import org.richfaces.model.Ordering;

                              import org.richfaces.model.SortField2;

                              What can I do to migrate my version of  ModifiableDataModel to RF 4.0?

                              Thank you for your answers!

                               

                              import org.richfaces.model.Modifiable;
                              import org.richfaces.model.Ordering;
                              import org.richfaces.model.SortField2;

                              • 12. Re: pagination and lazy data loding
                                ilya40umov

                                I've started a new discussion about the problem with migration to RF 4.0.

                                It's there: http://community.jboss.org/thread/160670

                                • 13. Re: pagination and lazy data loding
                                  ilya_shaikovsky

                                  updated new thread.