1

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

部分服务器端代码:

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();
    }
}
4

0 回答 0