LazyDataModel调用了两次

时间:2013-03-12 19:35:56

标签: java jsf primefaces

我使用来自primefaces的数据表来显示记录列表。 但是在导航到页面时它会调用load内部方法(overriden)两次。此行为会影响性能。

部分服务器端代码:

public void getInternalList() {    
    try {

        dataList = service.getInternalDetails(userId, 0, 5);

        if (null != dataList) {

            // Getting the current page data using lazy loading
            lazyModelEmployees = new LazyDataModel<Employee>() {
                @Override
                public List<Employee> load(int first, int pageSize, String arg2, SortOrder arg3, Map<String, String> arg4) {
                    List<Employee> currentPageEmployeeList = null;

                    try {
                        currentPageEmployeeList = service.getInternalDetails(userId, first, pageSize);
                    } catch (Exception e) {
                        exceptionHandler(e);
                    }

                    if (arg2 != null) {
                        Collections.sort(currentPageEmployeeList, new LazySorter(arg2, arg3));
                    }
                    int dataSize = currentPageEmployeeList.size();
                    this.setRowCount(dataSize);

                    if (dataSize > pageSize) {
                        try {
                            return currentPageEmployeeList.subList(first, first + pageSize);
                        } catch (IndexOutOfBoundsException e) {
                            return currentPageEmployeeList.subList(first, first + (dataSize % pageSize));
                        }
                    } else {
                        return currentPageEmployeeList;
                    }

                }
            };
            lazyModelEmployees.setRowCount(dataList.size());
            lazyModelEmployees.setPageSize(5);
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}

0 个答案:

没有答案