Skip to content

Commit

Permalink
feat(sheet): Invoke renderResponse when decode lazyUpdate to render R…
Browse files Browse the repository at this point in the history
…esponse immediate

issue: TOBAGO-2371
  • Loading branch information
bohmber committed Nov 26, 2024
1 parent 3229bce commit 797536d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -305,6 +306,10 @@ public boolean visitTree(final VisitContext context, final VisitCallback callbac
if (skipIterationHint) {
return false;
}
Collection<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<VisitHint> visitHints = EnumSet.copyOf(visitContext.getHints());
visitHints.add(VisitHint.SKIP_ITERATION);
VisitContext newVisitContext = new VisitContextWrapper(visitContext) {
Expand All @@ -435,6 +486,15 @@ public Set<VisitHint> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
xmlns:ui="jakarta.faces.facelets">
<ui:param name="title" value="Lazy Loading Large Data"/>
<tc:sheet value="#{sheetController.hugeSolarList}" id="sheet" var="luminary"
rows="20" markup="small" lazy="true"
lazyRows="20" markup="small" lazy="true"
showRowRange="none" showDirectLinks="none" showPageRange="none">
<tc:style maxHeight="500px"/>
<tc:column label="Name">
Expand Down

0 comments on commit 797536d

Please sign in to comment.