Following is an example of the code to implement Lazydatamodel:
Mymb.java
List<NameClass> listResult = new LazyDataModel<NameClass>() {
private static final long serialVersionUID = 1L;
@Override
public List<NameClass> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
List<NameClass> result = dao.findReg(....., pageSize, page);
setRowCount(numberOfResult);
return result;
}
};
getListResult() {..}
setListResult(List<NameClass> l ) {...}
myPage.xhtml
<p:dataTable lazy="true"
value="#{myMB.listResult}"
var="model"
paginator="true"
rows="#{myMB.pageSize}"
paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" >
Taking advantage, below the solution in case the pager does not restart:
1 - On the datatable screen, put the tag below, as the most appropriate action in your case. In mine, when closing the modal I call a Istener:
<p:ajax event="close" listener="#{myMB.onCloseModal}"/>
2- On the button that closes the modal, put "PF('dialogId'). clearFilters();" :
<h:commandLink onclick="PF('dialogWidget').hide(); PF('dialogId').clearFilters();"
3 - No Mymb:
public void onCloseModal(CloseEvent event){
pageItem = 1;
//pra funcionar o reset da paginaçao. E reduzir linhas de código. O ideal é que o nome da datatable de item seja o mesmo nome do "dialog+DtTable"
String nomeDataTable = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("javax.faces.source");
if( StringUtils.isNotEmpty(nomeDataTable) ){
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent(nomeDataTable+"DtTable");
dataTable.setFirst(0);
dataTable.reset();
dataTable.setFilterBy(null);
dataTable.setSortBy(null);
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.update(nomeDataTable);
}
}
I already have paging, the problem is that when the list method is called it loads the 14 thousand records from the bank.
– DiegoAugusto
see if I contributed anything else after EDIT
– Pedro Laini
It got me a little confused as I had seen this about Lazy: http://blog.algaworks.com/paginacao-de-datatable-do-primefaces-com-lazy-loading/
– DiegoAugusto
From what I read it is ideal to work with queries that return thousands of records and to avoid memory bursting
– DiegoAugusto
ah yes... the Lazy that is talking there is of the datatable... the Lazy that I spoke in the answer is of the list objects, with its bank relationships with other entities...
– Pedro Laini
see the response issue
– Pedro Laini
I’ll take a look
– DiegoAugusto