p:dataTable selections are lost after paginating a LazyDataModel

后端 未结 5 1255
春和景丽
春和景丽 2021-01-04 00:31

My problem is that after I\'ve selected a few items on the 1st page, if I paginate to another page and come back, my initial selections are not shown. I\'ve tried to impleme

5条回答
  •  花落未央
    2021-01-04 01:26

    Just implement the property bound to selection property of DataTable (selection="#{pageBackingForm.selectedEntityList}") like this and it will work :

        private Map> selectedEntityListMap = new Hashtable<>();
    
        public List getSelectedEntityList() {
            return selectedEntityListMap.get(getCurrentEntitySelectionPage());
        }
    
        public void setSelectedEntityList(List selectedEntityList) {
            if (selectedEntityList == null) {
                selectedEntityListMap.remove(getCurrentEntitySelectionPage());
                return;
            }
    
            selectedEntityListMap.put(getCurrentEntitySelectionPage(), selectedEntityList);
        }
    
        public Integer getCurrentEntitySelectionPage() {
            DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("formId:dataTableId");
            return dataTable.getPage();
        }
    

提交回复
热议问题