diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java index 9e0758f304..b9447d5284 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIData.java @@ -42,6 +42,7 @@ import javax.swing.tree.TreeNode; import java.io.IOException; import java.lang.invoke.MethodHandles; +import java.util.Collection; import java.util.List; /** @@ -305,6 +306,10 @@ public boolean visitTree(final VisitContext context, final VisitCallback callbac if (skipIterationHint) { return false; } + Collection subtreeIdsToVisit = context.getSubtreeIdsToVisit(this); + if (subtreeIdsToVisit == null || subtreeIdsToVisit.isEmpty()) { + return false; + } // save the current row index final int oldRowIndex = getRowIndex(); // set row index to -1 to process the facets and to get the rowless clientId diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java index 88b9f67337..5c2f19ea63 100644 --- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java +++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUISheet.java @@ -19,10 +19,12 @@ package org.apache.myfaces.tobago.internal.component; +import jakarta.faces.component.UINamingContainer; import org.apache.myfaces.tobago.component.Attributes; import org.apache.myfaces.tobago.component.Pageable; import org.apache.myfaces.tobago.component.Visual; import org.apache.myfaces.tobago.event.PageActionEvent; +import org.apache.myfaces.tobago.event.SheetAction; import org.apache.myfaces.tobago.event.SheetStateChangeEvent; import org.apache.myfaces.tobago.event.SheetStateChangeListener; import org.apache.myfaces.tobago.event.SheetStateChangeSource; @@ -332,6 +334,56 @@ public int getFirstRowIndexOfLastPage() { } } + @Override + public void processDecodes(FacesContext context) { + // Do decode without children of all columns + if (isLazyUpdate(context)) { + try { + pushComponentToEL(context, this); + if (!isRendered()) { + return; + } + setRowIndex(-1); + if (this.getFacetCount() > 0) { + for (UIComponent facet : getFacets().values()) { + facet.decode(context); + } + } + for (int i = 0, childCount = getChildCount(); i < childCount; i++) { + UIComponent child = getChildren().get(i); + if (child instanceof UIColumn) { + try { + child.pushComponentToEL(context, child); + if (!child.isRendered()) { + // Column is not visible + continue; + } + } finally { + child.popComponentFromEL(context); + } + if (child.getFacetCount() > 0) { + for (UIComponent facet : child.getFacets().values()) { + facet.decode(context); + } + } + } + } + // skip children of column + setRowIndex(-1); + try { + decode(context); + } catch (RuntimeException e) { + context.renderResponse(); + throw e; + } + } finally { + popComponentFromEL(context); + } + } else { + super.processDecodes(context); + } + } + @Override public void processUpdates(final FacesContext context) { super.processUpdates(context); @@ -419,9 +471,8 @@ public void broadcast(final FacesEvent facesEvent) throws AbortProcessingExcepti @Override public boolean visitTree(VisitContext visitContext, VisitCallback callback) { - boolean lazyUpdate = visitContext.getFacesContext().getExternalContext() - .getRequestParameterMap().containsKey("tobago.sheet.lazyFirstRow"); - if (lazyUpdate && PhaseId.APPLY_REQUEST_VALUES.equals(visitContext.getFacesContext().getCurrentPhaseId())) { + final FacesContext facesContext = visitContext.getFacesContext(); + if (isLazyUpdate(facesContext) && PhaseId.APPLY_REQUEST_VALUES.equals(visitContext.getFacesContext().getCurrentPhaseId())) { Set visitHints = EnumSet.copyOf(visitContext.getHints()); visitHints.add(VisitHint.SKIP_ITERATION); VisitContext newVisitContext = new VisitContextWrapper(visitContext) { @@ -435,6 +486,15 @@ public Set getHints() { return super.visitTree(visitContext, callback); } + private boolean isLazyUpdate(FacesContext facesContext) { + final String sourceId = facesContext.getExternalContext().getRequestParameterMap().get("jakarta.faces.source"); + final String clientId = getClientId(facesContext); + + final String sheetClientIdWithAction = clientId + UINamingContainer.getSeparatorChar(facesContext) + Pageable.SUFFIX_PAGE_ACTION + SheetAction.lazy; + + return sheetClientIdWithAction.equals(sourceId); + } + public void init(final FacesContext facesContext) { sort(facesContext, null); layoutHeader(); diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/90-lazy/Sheet_Lazy.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/90-lazy/Sheet_Lazy.xhtml index 81e7b21d10..45d55ce8ba 100644 --- a/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/90-lazy/Sheet_Lazy.xhtml +++ b/tobago-example/tobago-example-demo/src/main/webapp/content/080-sheet/90-lazy/Sheet_Lazy.xhtml @@ -23,7 +23,7 @@ xmlns:ui="jakarta.faces.facelets">