2121
2222import org .apache .wicket .MetaDataKey ;
2323import org .apache .wicket .page .IManageablePage ;
24+ import org .apache .wicket .request .IRequestCycle ;
2425import org .apache .wicket .request .cycle .RequestCycle ;
2526import org .slf4j .Logger ;
2627import org .slf4j .LoggerFactory ;
@@ -107,9 +108,10 @@ public void end(IPageContext context)
107108 public void detach (IPageContext context )
108109 {
109110 RequestData requestData = getRequestData (context );
111+ IRequestCycle requestCycle = RequestCycle .get ();
110112 for (IManageablePage page : requestData .pages ())
111113 {
112- if (isPageStateless (page ) == false )
114+ if (isPageStateless (page ) == false && shouldSerializePage ( requestCycle , page ) )
113115 {
114116 getDelegate ().addPage (context , page );
115117 }
@@ -119,6 +121,21 @@ public void detach(IPageContext context)
119121 getDelegate ().detach (context );
120122 }
121123
124+ /**
125+ * Give the opportunity to skip some serializations. E.g. we have some AJAX behavior that is sending some
126+ * info from client to page but page structure didn't change at all and nothing is repainted via AJAX.
127+ * But this will trigger a serialization. Returning false here would prevent that request from doing a
128+ * page serialization. For heavy pages this can really make a difference.
129+ *
130+ * @param requestCycle The request
131+ * @param page The {@link IManageablePage}
132+ * @return <code>true</code> if page should be serialized for this request. The default is true.
133+ */
134+ protected boolean shouldSerializePage (IRequestCycle requestCycle , IManageablePage page )
135+ {
136+ return true ;
137+ }
138+
122139 private boolean isPageStateless (final IManageablePage page ) {
123140 boolean isPageStateless ;
124141 try
0 commit comments