Efficient JSF Pagination

后端 未结 4 655
谎友^
谎友^ 2020-12-06 11:23

Whats the most efficient way of doing pagination in JSF 2.0 app? I use Primefaces datatable and it is intelligent enough to perform pagination by itself with no coding at al

相关标签:
4条回答
  • 2020-12-06 11:32

    Important note depending on which version of Primefaces you are using. Starting with 3.0.M2 (I think) if you want to use the row select feature you must implement a SelectableDataModel. This breaks a lot of legacy code and there were a number of bitches about that.

    Easiest thing to do is to create an inner class like this:

    private MyDataModel dataModel = null;
    
    public MyDataModel getDataModel() {
       if (dataModel != null) return dataModel;
       dataModel = new MyDataModel(some list);
       return dataModel;
    }
    
    public static class MyDataModel extends ListDataModel<SomeRecord>
            implements SelectableDataModel<SomeRecord> {
    
        MyDataModel(List<SomeRecord> source) {
            super(source);
        }
     etc.
    

    Then the value attribute to p:dataTable becomes #{bean.dataModel}.

    Good luck.

    0 讨论(0)
  • 2020-12-06 11:34

    I have found that the built in pagination feature of the Primefaces data table is one of the best features and did a good amount of load testing on it, bringing in recordsets with over 30,000 Hibernate entities and found the performance to be lackluster. This of course means that you will have 30,000 entities in session so I have the following in my web.xml to help by storing session on the server side.

    <context-param>
      <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
      <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
      <param-value>server</param-value>
    </context-param>
    

    This will reduce the size of the ViewState allowing request/response size to be greatly reduced however server side memory can suffer enormously by doing this.

    Another potential option in some JSF implementations to help mitigate the size of ViewStat or session memory usage is compression. The following link describes a number of SUN RI and MyFaces JSF configuration parameters that can be set, some of which give the option of compression of the session state. http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Frweb_jsfengine.html

    As far as learning more about how the Primefaces DataTable pagination feature works, why not go straight to the source? Primefaces is after all an open source project, so just look at the code and see what you can learn: http://code.google.com/p/primefaces/source/browse/#svn%2Fprimefaces

    0 讨论(0)
  • 2020-12-06 11:40

    In a production app, we've used a lazy datamodel to deal with 700000 records in db. I'd suggest using M3 which has fixes on lazy datatable cases.

    0 讨论(0)
  • 2020-12-06 11:45

    You need to use LazyDataModel in order to have only the rows in memory which the client actually needs to see. See also the example in PrimeFaces showcase. This does pagination at DB level which is what you ultimately want.

    RichFaces supports by the way the same in flavor of ArrangableDataModel, here's the RichFaces showcase example.

    0 讨论(0)
提交回复
热议问题