This does not work, because the load() method is called during the Render response phase (this can be checked by printing FacesContext.getCurrentInstance().getCurrentPhaseId() ) when all messages have already been processed.
The only workaround that worked for me was loading the data into the DataTable's "page" event listener.
HTML:
<p:dataTable value="#{controller.model}" binding="#{controller.table}"> <p:ajax event="page" listener="#{controller.onPagination}" /> </p:dataTable>
Controller:
private List<DTO> listDTO; private int rowCount; private DataTable table; private LazyDataModel<DTO> model = new LazyDataModel<DTO>() { @Override public List<DTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, String> filters) { setRowCount(rowCount); return listDTO; } }; public void onPagination(PageEvent event) { FacesContext ctx = FacesContext.getCurrentInstance(); Map<String, String> params = ctx.getExternalContext() .getRequestParameterMap();
Hope this helps.
source share