Skip to content

Commit

Permalink
[WICKET-7059] make easier to skip some page serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
reiern70 committed Jun 5, 2023
1 parent d8b64cf commit 22bc9fb
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 <code>true</code> 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
Expand Down

0 comments on commit 22bc9fb

Please sign in to comment.