When using lazy dataTable, another component is not updated / data of the second component is one request

I have PrimeFaces p:dataTable and lazy loading is enabled by implementing LazyDataModel .

Search results are stored in a DataTable, so when a search query is executed, the search service retrieves only the required (paginated) data. It works great.

When executing an ajax request with p:commandButton :

 <p:commandButton id="searchCmdBtn" value="Search" action="#{searchBean.search}" update=":resultForm:resultList :filterForm:filterMenu :resultForm:messages" ajax="true" /> 

dataTable is updated correctly, but not filterMenu in filterForm (differnt forms, bcz using p:layout ).

The Menu filter is one request. This means that when I click the search button again, the Menu filter is updated when t is only updated after the second ajax request

Bean

 @ManagedBean @ViewScoped public class SearchBean implements Serializable { private LazyDataModel<Entity> lazyDataModel; private MenuModel filterMenuModel = new DefaultMenuModel(); private SearchResult searchResult = null; public void search() { // lazy call getLazyDataModel(); if (searchResult != null) { buildFilterMenu(searchResult); } } private void initializeDataModel() { lazyDataModel = new LazyDataModel<Entity>() { private static final long serialVersionUID = 1L; @Override public List<Entity> load(int first, int pageSize, List<SortMeta> multiSortMeta, Map<String, String> filters) { // handling sorting and filtering // get search results try { setSearchResult(searchService.getEntities(queryText, selectedQueryOperand, getFilterOptions(), first, (first + pageSize), multiSortMeta)); } catch (Exception e) { // handle exception } if (searchResult == null) { return null; } List<Entity> resultEntities = searchResult.getResultEntities(); // total count this.setRowCount((int) searchResult.getTotalSize()); return resultEntities; } // other override-methods }; } public void buildFilterMenu() { // builds the filterMenu depending on searchResults } // getters and setters public LazyDataModel<Entity> getLazyDataModel() { if (lazyDataModel == null) { initializeDataModel(); } return lazyDataModel; } } 

filters.xhtml

 <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui" xmlns:fn="http://java.sun.com/jsp/jstl/functions"> <p:panelMenu id="filterMenu" model="#{searchBean.filterMenuModel}" /> </ui:composition> 
+6
source share
1 answer

After searching the PF forum, I found the main reason:

The dataTable Lazy load () method is called during the render response phase

To learn about the phases, read this BalusC JSF Life Cycle Tutorial

Solutions for displaying messages (for example: p:messages or p:growl ):


See also:

+9
source

Source: https://habr.com/ru/post/945291/


All Articles