From d57ed6e622e4fe75e0a6f3c71318a847b8a6ae70 Mon Sep 17 00:00:00 2001 From: reiern70 Date: Fri, 19 Jun 2026 16:00:51 -0500 Subject: [PATCH 1/2] [https://github.com/apache/wicket/issues/1492] make partial page update creation pluggable. --- .../wicket/ajax/AjaxRequestHandler.java | 21 ++++++++++++++----- .../apache/wicket/page/PartialPageUpdate.java | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestHandler.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestHandler.java index d9a1d386ad4..c0c650a807f 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestHandler.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestHandler.java @@ -83,10 +83,10 @@ public class AjaxRequestHandler extends AbstractPartialPageRequestHandler implem private final PartialPageUpdate update; /** a set of listeners */ - private Set listeners = null; + protected Set listeners = null; /** */ - private final Set respondListeners = new HashSet<>(); + protected final Set respondListeners = new HashSet<>(); /** see https://issues.apache.org/jira/browse/WICKET-3564 */ protected transient boolean respondersFrozen; @@ -104,7 +104,18 @@ public AjaxRequestHandler(final Page page) { super(page); - update = new XmlPartialPageUpdate(page) + update = newPartialPageUpdate(page); + } + + /** + * Factory method for {@link PartialPageUpdate}'s + * + * @param page The {@link Page} + * @return an instance of {@link PartialPageUpdate} + */ + protected PartialPageUpdate newPartialPageUpdate(final Page page) + { + return new XmlPartialPageUpdate(page) { /** * Freezes the {@link AjaxRequestHandler#listeners} before firing the event and @@ -130,7 +141,7 @@ protected void onBeforeRespond(final Response response) /** * Freezes the {@link AjaxRequestHandler#listeners}, and does not un-freeze them as the * events will have been fired by now. - * + * * @param response * the response to write to */ @@ -143,7 +154,7 @@ protected void onAfterRespond(final Response response) if (listeners != null) { final Map components = Collections - .unmodifiableMap(markupIdToComponent); + .unmodifiableMap(markupIdToComponent); for (AjaxRequestTarget.IListener listener : listeners) { diff --git a/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java b/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java index 98fb9880a72..67871bdd62b 100644 --- a/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java +++ b/wicket-core/src/main/java/org/apache/wicket/page/PartialPageUpdate.java @@ -75,7 +75,7 @@ public abstract class PartialPageUpdate * Length of the script block that combined scripts are wrapped in. This includes the script tag, * CDATA and if CSP is enabled also the nonce. */ - private static final int SCRIPT_BLOCK_LENGTH = 100; + protected static final int SCRIPT_BLOCK_LENGTH = 100; /** * A list of scripts (JavaScript) which should be executed on the client side before the From 17996316bef6173af599e5c9a15b57b78b28c8d3 Mon Sep 17 00:00:00 2001 From: reiern70 Date: Wed, 1 Jul 2026 13:15:54 -0500 Subject: [PATCH 2/2] [https://github.com/apache/wicket/issues/1492] make partial page update creation pluggable. --- .../wicket/ajax/AjaxRequestHandler.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestHandler.java b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestHandler.java index c0c650a807f..fb0ba56c258 100644 --- a/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestHandler.java +++ b/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxRequestHandler.java @@ -80,7 +80,7 @@ public class AjaxRequestHandler extends AbstractPartialPageRequestHandler implem /** * Collector of page updates. */ - private final PartialPageUpdate update; + private PartialPageUpdate update; /** a set of listeners */ protected Set listeners = null; @@ -103,8 +103,6 @@ public class AjaxRequestHandler extends AbstractPartialPageRequestHandler implem public AjaxRequestHandler(final Page page) { super(page); - - update = newPartialPageUpdate(page); } /** @@ -185,13 +183,16 @@ public void addListener(AjaxRequestTarget.IListener listener) throws IllegalStat @Override public PartialPageUpdate getUpdate() { + if (update == null) { + update = newPartialPageUpdate(getPage()); + } return update; } @Override public final Collection getComponents() { - return update.getComponents(); + return getUpdate().getComponents(); } /** @@ -205,7 +206,7 @@ public void detach(final IRequestCycle requestCycle) logData = new PageLogData(getPage()); } - update.detach(requestCycle); + getUpdate().detach(requestCycle); } /** @@ -217,7 +218,7 @@ public boolean equals(final Object obj) if (obj instanceof AjaxRequestHandler) { AjaxRequestHandler that = (AjaxRequestHandler)obj; - return update.equals(that.update); + return getUpdate().equals(that.update); } return false; } @@ -229,7 +230,7 @@ public boolean equals(final Object obj) public int hashCode() { int result = "AjaxRequestHandler".hashCode(); - result += update.hashCode() * 17; + result += getUpdate().hashCode() * 17; return result; } @@ -276,7 +277,7 @@ public final void respond(final IRequestCycle requestCycle) final String encoding = app.getRequestCycleSettings().getResponseRequestEncoding(); // Set content type based on markup type for page - update.setContentType(response, encoding); + getUpdate().setContentType(response, encoding); // Make sure it is not cached by a client response.disableCaching(); @@ -287,7 +288,7 @@ public final void respond(final IRequestCycle requestCycle) // WICKET-7074 we need to write to a temporary buffer, otherwise, if an exception is produced, // and a redirect is done we will end up with a malformed XML final StringResponse bodyResponse = new StringResponse(); - update.writeTo(bodyResponse, encoding); + getUpdate().writeTo(bodyResponse, encoding); if (filters == null || filters.isEmpty()) { response.write(bodyResponse.getBuffer()); @@ -301,7 +302,7 @@ public final void respond(final IRequestCycle requestCycle) private boolean shouldRedirectToPage(IRequestCycle requestCycle) { - if (update.containsPage()) + if (getUpdate().containsPage()) { return true; } @@ -344,7 +345,7 @@ private CharSequence invokeResponseFilters(final StringResponse contentResponse, @Override public String toString() { - return "[AjaxRequestHandler@" + hashCode() + " responseObject [" + update + "]"; + return "[AjaxRequestHandler@" + hashCode() + " responseObject [" + getUpdate() + "]"; } /**