Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ public class AjaxRequestHandler extends AbstractPartialPageRequestHandler implem
/**
* Collector of page updates.
*/
private final PartialPageUpdate update;
private PartialPageUpdate update;

/** a set of listeners */
private Set<AjaxRequestTarget.IListener> listeners = null;
protected Set<AjaxRequestTarget.IListener> listeners = null;

/** */
private final Set<ITargetRespondListener> respondListeners = new HashSet<>();
protected final Set<ITargetRespondListener> respondListeners = new HashSet<>();

/** see https://issues.apache.org/jira/browse/WICKET-3564 */
protected transient boolean respondersFrozen;
Expand All @@ -103,8 +103,17 @@ public class AjaxRequestHandler extends AbstractPartialPageRequestHandler implem
public AjaxRequestHandler(final Page page)
{
super(page);
}

update = new XmlPartialPageUpdate(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
Expand All @@ -130,7 +139,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
*/
Expand All @@ -143,7 +152,7 @@ protected void onAfterRespond(final Response response)
if (listeners != null)
{
final Map<String, Component> components = Collections
.unmodifiableMap(markupIdToComponent);
.unmodifiableMap(markupIdToComponent);

for (AjaxRequestTarget.IListener listener : listeners)
{
Expand Down Expand Up @@ -174,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<? extends Component> getComponents()
{
return update.getComponents();
return getUpdate().getComponents();
}

/**
Expand All @@ -194,7 +206,7 @@ public void detach(final IRequestCycle requestCycle)
logData = new PageLogData(getPage());
}

update.detach(requestCycle);
getUpdate().detach(requestCycle);
}

/**
Expand All @@ -206,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;
}
Expand All @@ -218,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;
}

Expand Down Expand Up @@ -265,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();
Expand All @@ -276,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());
Expand All @@ -290,7 +302,7 @@ public final void respond(final IRequestCycle requestCycle)

private boolean shouldRedirectToPage(IRequestCycle requestCycle)
{
if (update.containsPage())
if (getUpdate().containsPage())
{
return true;
}
Expand Down Expand Up @@ -333,7 +345,7 @@ private CharSequence invokeResponseFilters(final StringResponse contentResponse,
@Override
public String toString()
{
return "[AjaxRequestHandler@" + hashCode() + " responseObject [" + update + "]";
return "[AjaxRequestHandler@" + hashCode() + " responseObject [" + getUpdate() + "]";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down