Skip to content

Commit

Permalink
Fix #11452 - 13.0.6 DataTable: LazyDataModel.load gets invoked multip…
Browse files Browse the repository at this point in the history
…le times (#11461)
  • Loading branch information
melloware committed Feb 19, 2024
1 parent 01adab8 commit 4f3be01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,6 @@ protected void encodeRows(FacesContext context, DataTable table, int first, int
String clientId = table.getClientId(context);
List<SummaryRow> summaryRows = table.getSummaryRows();
HeaderRow headerRow = table.getHeaderRow();
ELContext elContext = context.getELContext();

SortMeta sort = table.getHighestPriorityActiveSortMeta();
boolean encodeHeaderRow = headerRow != null && headerRow.isEnabled() && sort != null;
Expand All @@ -1102,15 +1101,15 @@ protected void encodeRows(FacesContext context, DataTable table, int first, int

table.setRowIndex(i);

if (encodeHeaderRow && (i == first || !isInSameGroup(context, table, i, -1, sort.getSortBy(), elContext))) {
if (encodeHeaderRow && (i == first || !isInSameGroup(context, table, i, -1, sort.getSortBy(), false))) {
table.setRowIndex(i);
encodeHeaderRow(context, table, headerRow);
}

table.setRowIndex(i);
encodeRow(context, table, clientId, i, columnStart, columnEnd);

if (encodeSummaryRow && !isInSameGroup(context, table, i, 1, sort.getSortBy(), elContext)) {
if (encodeSummaryRow && !isInSameGroup(context, table, i, 1, sort.getSortBy(), i == last - 1)) {
table.setRowIndex(i);
encodeSummaryRow(context, summaryRows, sort);
}
Expand Down Expand Up @@ -1598,20 +1597,19 @@ protected void encodeSubTable(FacesContext context, DataTable table, SubTable su
}

protected boolean isInSameGroup(FacesContext context, DataTable table, int currentRowIndex, int step, ValueExpression groupByVE,
ELContext elContext) {

boolean loadFirstRowOfNextPage) {
ELContext elContext = context.getELContext();
table.setRowIndex(currentRowIndex);
Object currentGroupByData = groupByVE.getValue(elContext);

int nextRowIndex = currentRowIndex + step;

Object nextGroupByData;

// in case of a lazy DataTable, the LazyDataModel currently only loads rows inside the current page; we need a small hack here
// 1) get the rowData manually for the next row
// 2) put it into request-scope
// 3) invoke the groupBy ValueExpression
if (table.isLazy()) {
// An additional check is required to ensure summaryRow will be rendered in case
// number of rows of the current page is equals to the number of items in the current group (otherwise, it'll never be rendered)
// see #9077
if (loadFirstRowOfNextPage && table.isLazy()) {
Object nextRowData = table.getLazyDataModel().getRowData(nextRowIndex, table.getActiveSortMeta(), table.getActiveFilterMeta());
if (nextRowData == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,16 @@ public T getRowData(String rowKey) {
+ ", when basic rowKey algorithm is not used [component=%s,view=%s]."));
}

/**
* Loads a single row for the rowIndex provided.
*
* @param rowIndex the row index to load
* @param sortBy a map with all sort information (only relevant for DataTable, not for eg DataView)
* @param filterBy a map with all filter information (only relevant for DataTable, not for eg DataView)
* @return the data
*/
public T getRowData(int rowIndex, Map<String, SortMeta> sortBy, Map<String, FilterMeta> filterBy) {
List<T> loaded = load(rowIndex, rowIndex + 1, sortBy, filterBy);
List<T> loaded = load(rowIndex, 1, sortBy, filterBy);
if (loaded == null || loaded.isEmpty()) {
return null;
}
Expand Down

0 comments on commit 4f3be01

Please sign in to comment.