Skip to content

Let a partial page update deliver named data to client-side code - #1907

Open
papegaaij wants to merge 3 commits into
masterfrom
partial-update-data
Open

papegaaij wants to merge 3 commits into
masterfrom
partial-update-data

Conversation

@papegaaij

Copy link
Copy Markdown
Contributor

An Ajax response can now carry named data for client-side code, besides components, header contributions and scripts. On the server, addData(name, value) on IPartialPageRequestHandler (and so on AjaxRequestTarget and the web socket request handler) adds an entry. It is written as a <data name="…"> element in the <ajax-response>, and both Ajax libraries publish it on the new topic '/ajax/call/data'.

Until now, client-side code that needed a value from the server got it through an evaluated script, typically appendJavaScript("x.update(" + json + ")") with an escaping helper. That mixes data with code, has to escape correctly for a script context, and has to pass the Trusted Types policy of #1880. A data entry is never interpreted or evaluated by Wicket. It is published in order, after the components have been replaced and the scripts evaluated, and before the success handlers run. It also works for updates pushed over a web socket.

This is split out of #1834 (Wicket Islands), which uses it as the result channel of its server calls, following the review there. It stands on its own, and other libraries can use it in place of appendJavaScript.

Changes

  • IPartialPageRequestHandler#addData(String, CharSequence), implemented in AbstractPartialPageRequestHandler.
  • PartialPageUpdate#addData and the abstract writeData, implemented in XmlPartialPageUpdate as <data name="…"><![CDATA[…]]></data>.
  • wicket-ajax-jquery.js and wicket-ajax.js publish '/ajax/call/data' with (attrs, name, value). Over a web socket, attrs is an empty object.
  • Reference guide: the topic is listed with the other global Ajax events.
  • migration-to-12.md: a section on the two new abstract methods.

Compatibility

addData and writeData are new abstract methods. Applications using AjaxRequestTarget, the web socket request handler or XmlPartialPageUpdate see no change. A class that implements IPartialPageRequestHandler without extending AbstractPartialPageRequestHandler, or that extends PartialPageUpdate without extending XmlPartialPageUpdate, must implement the new method. writeData stays abstract: PartialPageUpdate does not know the response format, so a default could only drop the data silently.

Tests

XmlPartialPageUpdateTest and AjaxRequestHandlerTest cover the server side, and the QUnit tests in wicket-core/src/test/js/ajax.js cover both Ajax libraries. mvn clean verify -Pjs-test passes.

🤖 Generated with Claude Code

papegaaij and others added 3 commits November 5, 2026 18:57
An Ajax response could carry components, header contributions and
scripts, but no plain data. Client-side code that needed a value from the
server had to receive it through an evaluated script, for example by
appending JavaScript that stores JSON somewhere for later pickup. That
mixes data with code, depends on where the script happens to run, and
offers no ordering guarantee relative to the rest of the response.

IPartialPageRequestHandler (and with it AjaxRequestTarget and the
websocket request handler) now has addData(name, value). Each entry is
written as a <data name="..."> element in the <ajax-response>. Both Ajax
libraries publish it on the new topic '/ajax/call/data' with the call's
attributes, the name and the value, after the components have been
replaced and the scripts evaluated, and before the success handlers run.
Wicket delivers the value as text and never interprets it.

This adds an abstract method to IPartialPageRequestHandler, implemented
in AbstractPartialPageRequestHandler, and an abstract writeData to
PartialPageUpdate, implemented in XmlPartialPageUpdate. Applications that
use these classes see no change. A custom implementation that does not
extend those base classes has to implement the new method. The data part
is the foundation for embedding JavaScript framework components, which
need a result channel for server calls that is separate from scripts.

Migration guide: "IPartialPageRequestHandler#addData(String,
CharSequence) and PartialPageUpdate#writeData(Response, String,
CharSequence) are new abstract methods. Implementations that do not
extend AbstractPartialPageRequestHandler or XmlPartialPageUpdate must
implement them."

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the migration section

The review of the data part in pull request #1834 asked for two points
in the Javadoc of IPartialPageRequestHandler#addData. A partial update
pushed over a web socket belongs to no Ajax call, so the subscribers of
'/ajax/call/data' get an empty object as attrs; the Javadoc only spoke
of the attributes of the Ajax call. And every subscriber sees every
entry, with the name as the only thing telling them apart, so two
libraries choosing the same name would read each other's data; the
Javadoc now recommends a name prefixed with the library's name.

The data part added two abstract methods, which breaks implementations
that do not extend the base classes, so migration-to-12.md gets the
section the commit introducing them only drafted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.60870% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.84%. Comparing base (45a352a) to head (1337517).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1907      +/-   ##
============================================
+ Coverage     62.81%   62.84%   +0.03%     
- Complexity    11550    11559       +9     
============================================
  Files          1254     1254              
  Lines         48726    48748      +22     
  Branches       6867     6871       +4     
============================================
+ Hits          30606    30636      +30     
+ Misses        15431    15420      -11     
- Partials       2689     2692       +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants