diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java index c8034f5f4a0..d3a4244531e 100644 --- a/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java +++ b/wicket-core/src/main/java/org/apache/wicket/pageStore/RequestPageStore.java @@ -21,6 +21,7 @@ import org.apache.wicket.MetaDataKey; import org.apache.wicket.page.IManageablePage; +import org.apache.wicket.request.IRequestCycle; import org.apache.wicket.request.cycle.RequestCycle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -107,9 +108,10 @@ public void end(IPageContext context) public void detach(IPageContext context) { RequestData requestData = getRequestData(context); + IRequestCycle requestCycle = RequestCycle.get(); for (IManageablePage page : requestData.pages()) { - if (isPageStateless(page) == false) + if (isPageStateless(page) == false && shouldSerializePage(requestCycle, page)) { getDelegate().addPage(context, page); } @@ -119,6 +121,21 @@ public void detach(IPageContext context) getDelegate().detach(context); } + /** + * Give the opportunity to skip some serializations. E.g. we have some AJAX behavior that is sending some + * info from client to page but page structure didn't change at all and nothing is repainted via AJAX. + * But this will trigger a serialization. Returning false here would prevent that request from doing a + * page serialization. For heavy pages this can really make a difference. + * + * @param requestCycle The request + * @param page The {@link IManageablePage} + * @return true if page should be serialized for this request. The default is true. + */ + protected boolean shouldSerializePage(IRequestCycle requestCycle, IManageablePage page) + { + return true; + } + private boolean isPageStateless(final IManageablePage page) { boolean isPageStateless; try