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 @@ -83,10 +83,10 @@ public class AjaxRequestHandler extends AbstractPartialPageRequestHandler implem
private final 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 @@ -104,7 +104,18 @@ public AjaxRequestHandler(final Page page)
{
super(page);

update = new XmlPartialPageUpdate(page)
update = newPartialPageUpdate(page);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://stackoverflow.com/questions/3404301/whats-wrong-with-overridable-method-calls-in-constructors

It will be better to add another constructor public AjaxRequestHandler(final Page page, final PartialPageUpdate ppu)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me... checking

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factory method is better because constructor argument does not allow access to protected methods

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the overrideable method is called on an instance with unfinished construction.

}

/**
* 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 +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
*/
Expand All @@ -143,7 +154,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
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