Repository navigation
Conversation
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 Report❌ Patch coverage is 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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An Ajax response can now carry named data for client-side code, besides components, header contributions and scripts. On the server,
addData(name, value)onIPartialPageRequestHandler(and so onAjaxRequestTargetand 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 inAbstractPartialPageRequestHandler.PartialPageUpdate#addDataand the abstractwriteData, implemented inXmlPartialPageUpdateas<data name="…"><![CDATA[…]]></data>.wicket-ajax-jquery.jsandwicket-ajax.jspublish'/ajax/call/data'with(attrs, name, value). Over a web socket,attrsis an empty object.migration-to-12.md: a section on the two new abstract methods.Compatibility
addDataandwriteDataare new abstract methods. Applications usingAjaxRequestTarget, the web socket request handler orXmlPartialPageUpdatesee no change. A class that implementsIPartialPageRequestHandlerwithout extendingAbstractPartialPageRequestHandler, or that extendsPartialPageUpdatewithout extendingXmlPartialPageUpdate, must implement the new method.writeDatastays abstract:PartialPageUpdatedoes not know the response format, so a default could only drop the data silently.Tests
XmlPartialPageUpdateTestandAjaxRequestHandlerTestcover the server side, and the QUnit tests inwicket-core/src/test/js/ajax.jscover both Ajax libraries.mvn clean verify -Pjs-testpasses.🤖 Generated with Claude Code