From 1cc585b2d5449f9325ff47180c02635587a64252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Thu, 17 Oct 2024 17:58:15 +0300 Subject: [PATCH 1/6] force update. --- .../context/element/ContextElementRender.java | 2 ++ .../net/infumia/frame/element/Element.java | 3 +++ .../executor/PipelineExecutorElement.java | 5 +++- .../element/ContextElementRenderImpl.java | 14 ++++++++--- .../element/ElementEventHandlerItem.java | 8 +++---- .../infumia/frame/element/ElementImpl.java | 6 +++++ .../frame/element/ElementItemImpl.java | 11 +++++++++ .../ElementEventHandlerPagination.java | 6 ++--- .../pagination/ElementPaginationImpl.java | 24 +++++++++++++++---- .../pagination/ElementPaginationRich.java | 2 +- .../executor/PipelineExecutorElementImpl.java | 5 ++-- .../service/render/ServiceFirstRender.java | 2 +- 12 files changed, 68 insertions(+), 20 deletions(-) diff --git a/common/src/main/java/net/infumia/frame/context/element/ContextElementRender.java b/common/src/main/java/net/infumia/frame/context/element/ContextElementRender.java index c45e840..63d7198 100644 --- a/common/src/main/java/net/infumia/frame/context/element/ContextElementRender.java +++ b/common/src/main/java/net/infumia/frame/context/element/ContextElementRender.java @@ -7,4 +7,6 @@ public interface ContextElementRender extends ContextRender { @NotNull Element element(); + + boolean forced(); } diff --git a/common/src/main/java/net/infumia/frame/element/Element.java b/common/src/main/java/net/infumia/frame/element/Element.java index 5d22de0..23e7602 100644 --- a/common/src/main/java/net/infumia/frame/element/Element.java +++ b/common/src/main/java/net/infumia/frame/element/Element.java @@ -27,4 +27,7 @@ public interface Element { @NotNull CompletableFuture update(); + + @NotNull + CompletableFuture forceUpdate(); } diff --git a/common/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorElement.java b/common/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorElement.java index 07555b8..81761ad 100644 --- a/common/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorElement.java +++ b/common/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorElement.java @@ -10,7 +10,10 @@ public interface PipelineExecutorElement { @NotNull - CompletableFuture executeRender(@NotNull ContextRender context); + CompletableFuture executeRender( + @NotNull ContextRender context, + boolean forced + ); @NotNull CompletableFuture executeUpdate( diff --git a/core/src/main/java/net/infumia/frame/context/element/ContextElementRenderImpl.java b/core/src/main/java/net/infumia/frame/context/element/ContextElementRenderImpl.java index a2892f1..23a6ee2 100644 --- a/core/src/main/java/net/infumia/frame/context/element/ContextElementRenderImpl.java +++ b/core/src/main/java/net/infumia/frame/context/element/ContextElementRenderImpl.java @@ -8,13 +8,20 @@ public class ContextElementRenderImpl extends ContextRenderImpl implements ContextElementRender { private final Element element; + private final boolean forced; public ContextElementRenderImpl( @NotNull final ContextRender context, - @NotNull final Element element + @NotNull final Element element, + final boolean forced ) { super(context); this.element = element; + this.forced = forced; + } + + public ContextElementRenderImpl(@NotNull final ContextElementRender context) { + this(context, context.element(), context.forced()); } @NotNull @@ -23,7 +30,8 @@ public Element element() { return this.element; } - public ContextElementRenderImpl(@NotNull final ContextElementRender context) { - this(context, context.element()); + @Override + public boolean forced() { + return this.forced; } } diff --git a/core/src/main/java/net/infumia/frame/element/ElementEventHandlerItem.java b/core/src/main/java/net/infumia/frame/element/ElementEventHandlerItem.java index 2d41054..ad41a2b 100644 --- a/core/src/main/java/net/infumia/frame/element/ElementEventHandlerItem.java +++ b/core/src/main/java/net/infumia/frame/element/ElementEventHandlerItem.java @@ -33,7 +33,7 @@ public CompletableFuture handleRender( final ContextElementRender context = ctx.context(); final ElementItemRich element = (ElementItemRich) context.element(); if (element.shouldRender(context)) { - this.forceRender(element, context); + this.renderInternally(element, context); return CompletableFuture.completedFuture(ConsumerService.State.CONTINUE); } element.visible(false); @@ -80,7 +80,7 @@ public CompletableFuture handleUpdate( if (context.cancelled()) { return CompletableFuture.completedFuture(ConsumerService.State.CONTINUE); } - return element.pipelines().executeRender(context); + return element.pipelines().executeRender(context, context.forced()); } @NotNull @@ -96,7 +96,7 @@ private CompletableFuture checkOverlapping( final ElementRich overlapping = overlappingOptional.get(); return overlapping .pipelines() - .executeRender(context) + .executeRender(context, false) .thenCompose(__ -> { if (overlapping.visible()) { return CompletableFuture.completedFuture(ConsumerService.State.CONTINUE); @@ -150,7 +150,7 @@ private Optional findOverlappingElement( return Optional.empty(); } - private void forceRender( + private void renderInternally( @NotNull final ElementItemRich element, @NotNull final ContextElementRender delegate ) { diff --git a/core/src/main/java/net/infumia/frame/element/ElementImpl.java b/core/src/main/java/net/infumia/frame/element/ElementImpl.java index 1b0e02c..af01c8b 100644 --- a/core/src/main/java/net/infumia/frame/element/ElementImpl.java +++ b/core/src/main/java/net/infumia/frame/element/ElementImpl.java @@ -122,6 +122,12 @@ public CompletableFuture update() { throw new UnsupportedOperationException("This element cannot be updated!"); } + @NotNull + @Override + public CompletableFuture forceUpdate() { + throw new UnsupportedOperationException("This element cannot be updated!"); + } + @Override public String key() { return this.key; diff --git a/core/src/main/java/net/infumia/frame/element/ElementItemImpl.java b/core/src/main/java/net/infumia/frame/element/ElementItemImpl.java index 1dd6a87..8017ce4 100644 --- a/core/src/main/java/net/infumia/frame/element/ElementItemImpl.java +++ b/core/src/main/java/net/infumia/frame/element/ElementItemImpl.java @@ -102,6 +102,17 @@ public CompletableFuture update() { return this.pipelines.executeUpdate((ContextRender) this.parent, false); } + @NotNull + @Override + public CompletableFuture forceUpdate() { + Preconditions.state( + this.parent instanceof ContextRender, + "You cannot update the element '%s' when the parent is not a ContextRender!", + this + ); + return this.pipelines.executeUpdate((ContextRender) this.parent, true); + } + @NotNull @Override public PipelineExecutorElement pipelines() { diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java index da9f0ef..d744789 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java @@ -38,7 +38,7 @@ public CompletableFuture handleRender( pagination.updatePageSize(context); } return pagination - .loadCurrentPage(context) + .loadCurrentPage(context, context.forced()) .thenCompose(__ -> { pagination.visible(true); pagination.initialized(true); @@ -115,7 +115,7 @@ public CompletableFuture handleUpdate( .executeClear(context) .thenCompose(__ -> { pagination.clearElements(); - return pagination.pipelines().executeRender(context); + return pagination.pipelines().executeRender(context, context.forced()); }) .thenApply(__ -> { pagination.pageWasChanged(false); @@ -143,7 +143,7 @@ private CompletableFuture renderChild( final CompletableFuture[] futures = new CompletableFuture[elements.size()]; for (int i = 0; i < futures.length; i++) { final ElementRich element = (ElementRich) elements.get(i); - futures[i] = element.pipelines().executeRender(context); + futures[i] = element.pipelines().executeRender(context, context.forced()); } return CompletableFuture.allOf(futures).thenApply(__ -> ConsumerService.State.CONTINUE); } diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java index 16c83b0..a5fbea4 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java @@ -122,8 +122,11 @@ public void updatePageSize(@NotNull final ContextRender context) { @NotNull @Override - public CompletableFuture loadCurrentPage(@NotNull final ContextRender context) { - return this.loadSourceForTheCurrentPage(context).thenAccept(pageContents -> { + public CompletableFuture loadCurrentPage( + @NotNull final ContextRender context, + final boolean forced + ) { + return this.loadSourceForTheCurrentPage(context, forced).thenAccept(pageContents -> { if (pageContents.isEmpty()) { return; } @@ -333,6 +336,17 @@ public CompletableFuture update() { return this.pipelines.executeUpdate((ContextRender) this.parent(), false); } + @NotNull + @Override + public CompletableFuture forceUpdate() { + Preconditions.state( + this.parent() instanceof ContextRender, + "You cannot update the element '%s' when the parent is not a ContextRender!", + this + ); + return this.pipelines.executeUpdate((ContextRender) this.parent(), true); + } + @NotNull @Override public PipelineExecutorElement pipelines() { @@ -389,15 +403,15 @@ private void addComponentsForLayeredPagination( @NotNull private CompletableFuture> loadSourceForTheCurrentPage( - @NotNull final ContextBase context + @NotNull final ContextBase context, + final boolean forced ) { final boolean isLazy = this.sourceProvider.lazy(); final boolean reuseLazy = isLazy && this.initialized; - final boolean force = false; // TODO: portlek, Implement this. if ( (this.sourceProvider.provided() || reuseLazy) && !this.sourceProvider.computed() && - !force + !forced ) { final List currentSource = Preconditions.stateNotNull( this.currentSource, diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationRich.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationRich.java index 28876f2..c95e9ca 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationRich.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationRich.java @@ -25,7 +25,7 @@ public interface ElementPaginationRich void updatePageSize(@NotNull ContextRender context); @NotNull - CompletableFuture loadCurrentPage(@NotNull ContextRender context); + CompletableFuture loadCurrentPage(@NotNull ContextRender context, boolean forced); @NotNull Collection modifiableElements(); diff --git a/core/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorElementImpl.java b/core/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorElementImpl.java index e12d229..4bdfefc 100644 --- a/core/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorElementImpl.java +++ b/core/src/main/java/net/infumia/frame/pipeline/executor/PipelineExecutorElementImpl.java @@ -27,12 +27,13 @@ public PipelineExecutorElementImpl(@NotNull final ElementRich element) { @NotNull @Override public CompletableFuture executeRender( - @NotNull final ContextRender context + @NotNull final ContextRender context, + final boolean forced ) { return this.pipelines.render() .completeWith( new PipelineContextElements.Render( - new ContextElementRenderImpl(context, this.element) + new ContextElementRenderImpl(context, this.element, forced) ) ); } diff --git a/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceFirstRender.java b/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceFirstRender.java index e9a2cea..d5c1e29 100644 --- a/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceFirstRender.java +++ b/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceFirstRender.java @@ -36,7 +36,7 @@ public CompletableFuture handle(@NotNull final PipelineContextRender.Firs final CompletableFuture[] futures = new CompletableFuture[size]; for (int i = size; i > 0; i--) { final ElementRich element = (ElementRich) elements.get(i - 1); - futures[size - i] = element.pipelines().executeRender(context); + futures[size - i] = element.pipelines().executeRender(context, false); } return CompletableFuture.allOf(futures).thenApply(unused -> State.CONTINUE); } From aecd3922f712c36552c9acff1dd3db0c2686a042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Thu, 17 Oct 2024 18:25:35 +0300 Subject: [PATCH 2/6] simplify. --- .../element/pagination/ElementEventHandlerPagination.java | 8 ++++++-- .../frame/element/pagination/ElementPaginationImpl.java | 2 +- .../service/element/ServiceClickUpdateOnClick.java | 3 +-- .../service/render/ServiceFirstRenderWatchState.java | 4 ++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java index d744789..4b0b63c 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java @@ -128,8 +128,12 @@ public CompletableFuture handleUpdate( final List elements = pagination.elements(); final CompletableFuture[] futures = new CompletableFuture[elements.size()]; for (int i = 0; i < futures.length; i++) { - futures[i] = ((ElementRich) elements.get(i)).pipelines() - .executeUpdate(context, context.forced()); + final ElementRich element = (ElementRich) elements.get(i); + if (context.forced()) { + futures[i] = element.forceUpdate(); + } else { + futures[i] = element.update(); + } } return CompletableFuture.allOf(futures).thenApply(__ -> ConsumerService.State.CONTINUE); } diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java index a5fbea4..6b30be3 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java @@ -228,7 +228,7 @@ public void switchTo(final int pageIndex) { this.onPageSwitch.accept(host, this); } CompletableFutureExtensions.logError( - this.pipelines.executeUpdate(host, false), + this.update(), this.parent().frame().logger(), "An error occurred while updating the pagination '%s'.", this diff --git a/core/src/main/java/net/infumia/frame/pipeline/service/element/ServiceClickUpdateOnClick.java b/core/src/main/java/net/infumia/frame/pipeline/service/element/ServiceClickUpdateOnClick.java index 776b6f0..9c92a42 100644 --- a/core/src/main/java/net/infumia/frame/pipeline/service/element/ServiceClickUpdateOnClick.java +++ b/core/src/main/java/net/infumia/frame/pipeline/service/element/ServiceClickUpdateOnClick.java @@ -3,7 +3,6 @@ import java.util.concurrent.CompletableFuture; import net.infumia.frame.context.element.ContextElementClick; import net.infumia.frame.element.Element; -import net.infumia.frame.element.ElementRich; import net.infumia.frame.pipeline.PipelineServiceConsumer; import net.infumia.frame.pipeline.context.PipelineContextElement; import org.jetbrains.annotations.NotNull; @@ -28,7 +27,7 @@ public CompletableFuture handle(@NotNull final PipelineContextElement.Cli final ContextElementClick context = ctx.context(); final Element element = context.element(); if (element.updateOnClick()) { - return ((ElementRich) element).pipelines().executeUpdate(context, false); + return element.update(); } return CompletableFuture.completedFuture(State.CONTINUE); } diff --git a/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceFirstRenderWatchState.java b/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceFirstRenderWatchState.java index d74069e..49a89fe 100644 --- a/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceFirstRenderWatchState.java +++ b/core/src/main/java/net/infumia/frame/pipeline/service/render/ServiceFirstRenderWatchState.java @@ -57,7 +57,7 @@ private static void updateOnStateAccess( for (final net.infumia.frame.state.State state : states) { state.watchAccess(context, update -> CompletableFutureExtensions.logError( - element.pipelines().executeUpdate(context, false), + element.update(), context.frame().logger(), "An error occurred while updating element '%s' due to state '%s' access!", element.key(), @@ -78,7 +78,7 @@ private static void updateOnStateChange( for (final net.infumia.frame.state.State state : states) { state.watchUpdate(context, update -> CompletableFutureExtensions.logError( - element.pipelines().executeUpdate(context, false), + element.update(), context.frame().logger(), "An error occurred while updating element '%s' due to state '%s' change!", element.key(), From 0a3c9154c80067f50ca103ed9bfdd8e7476c38b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Thu, 17 Oct 2024 19:13:03 +0300 Subject: [PATCH 3/6] Update ElementEventHandlerPagination.java --- .../frame/element/pagination/ElementEventHandlerPagination.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java index 4b0b63c..3f3e09b 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java @@ -109,7 +109,7 @@ public CompletableFuture handleUpdate( ) { final ContextElementUpdate context = ctx.context(); final ElementPaginationRich pagination = (ElementPaginationRich) context.element(); - if (pagination.pageWasChanged()) { + if (pagination.pageWasChanged() || context.forced()) { return pagination .pipelines() .executeClear(context) From c1a9e8b55525e742ecf9e97bde853c9d041c0ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Thu, 17 Oct 2024 20:03:52 +0300 Subject: [PATCH 4/6] fix. --- .../ElementEventHandlerPagination.java | 2 +- .../pagination/ElementPaginationImpl.java | 41 ++++++++----------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java index 3f3e09b..399710f 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementEventHandlerPagination.java @@ -30,7 +30,7 @@ public CompletableFuture handleRender( ) { final ContextElementRender context = ctx.context(); final ElementPaginationRich pagination = (ElementPaginationRich) context.element(); - if (pagination.initialized() && !pagination.pageWasChanged()) { + if (pagination.initialized() && !pagination.pageWasChanged() && !context.forced()) { pagination.visible(true); return this.renderChild(context, pagination); } diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java index 6b30be3..9770c48 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java @@ -27,7 +27,6 @@ import net.infumia.frame.service.ConsumerService; import net.infumia.frame.slot.LayoutSlot; import net.infumia.frame.state.State; -import net.infumia.frame.state.StateRich; import net.infumia.frame.state.pagination.ElementConfigurer; import net.infumia.frame.state.pagination.StatePagination; import net.infumia.frame.util.Preconditions; @@ -433,29 +432,21 @@ private CompletableFuture> loadSourceForTheCurrentPage( } this.loading = true; - return ((StateRich) this.associated).manualUpdateWait( - context - ).thenCompose(__ -> { - if (this.sourceFactory == null) { - return CompletableFuture.completedFuture(Collections.emptyList()); - } - return this.sourceFactory.apply(context).thenCompose(result -> { - this.currentSource = result; - this.pageCount = this.calculatePagesCount(result); - this.loading = false; - return ((StateRich) this.associated).manualUpdateWait( - context - ).thenApply(value -> - !isLazy - ? result - : ElementPaginationImpl.splitSourceForPage( - this.currentPageIndex, - this.pageSize(), - this.pageCount, - result - ) - ); - }); + if (this.sourceFactory == null) { + return CompletableFuture.completedFuture(Collections.emptyList()); + } + return this.sourceFactory.apply(context).thenApply(result -> { + this.currentSource = result; + this.pageCount = this.calculatePagesCount(result); + this.loading = false; + return !isLazy + ? result + : ElementPaginationImpl.splitSourceForPage( + this.currentPageIndex, + this.pageSize(), + this.pageCount, + result + ); }); } @@ -502,7 +493,7 @@ private static List splitSourceForPage( if (src.size() <= pageSize) { return new ArrayList<>(src); } - if (index < 0 || (pagesCount > 0 && index > pagesCount)) { + if (index < 0 || (pagesCount > 0 && index >= pagesCount)) { throw new IndexOutOfBoundsException( String.format( "Page index must be between the range of 0 and %d. Given: %d", From 1321d998e400dfb64f0952233efa53156106ddef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Thu, 17 Oct 2024 20:34:04 +0300 Subject: [PATCH 5/6] Update ElementPaginationImpl.java --- .../frame/element/pagination/ElementPaginationImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java index 9770c48..cab276d 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java @@ -439,14 +439,14 @@ private CompletableFuture> loadSourceForTheCurrentPage( this.currentSource = result; this.pageCount = this.calculatePagesCount(result); this.loading = false; - return !isLazy - ? result - : ElementPaginationImpl.splitSourceForPage( + return isLazy + ? ElementPaginationImpl.splitSourceForPage( this.currentPageIndex, this.pageSize(), this.pageCount, result - ); + ) + : result; }); } From a5cd160d30282c46f6ce35d3d92dc9d3bcafee7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Thu, 17 Oct 2024 20:49:42 +0300 Subject: [PATCH 6/6] Update ElementPaginationImpl.java --- .../frame/element/pagination/ElementPaginationImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java index cab276d..e14bd95 100644 --- a/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java +++ b/core/src/main/java/net/infumia/frame/element/pagination/ElementPaginationImpl.java @@ -438,7 +438,11 @@ private CompletableFuture> loadSourceForTheCurrentPage( return this.sourceFactory.apply(context).thenApply(result -> { this.currentSource = result; this.pageCount = this.calculatePagesCount(result); + final int previousPage = Math.min(this.currentPageIndex, this.pageCount - 1); this.loading = false; + if (previousPage != this.currentPageIndex) { + this.switchTo(previousPage); + } return isLazy ? ElementPaginationImpl.splitSourceForPage( this.currentPageIndex,