Efficient JSF Pagination

后端 未结 4 668
谎友^
谎友^ 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
            implements SelectableDataModel {
    
        MyDataModel(List source) {
            super(source);
        }
     etc.
    

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

    Good luck.

提交回复
热议问题