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 63.95% 63.97% +0.01%
- Complexity 12265 12276 +11
============================================
Files 1276 1276
Lines 50398 50431 +33
Branches 7127 7132 +5
============================================
+ Hits 32232 32261 +29
- Misses 15402 15404 +2
- Partials 2764 2766 +2 🚀 New features to boost your workflow:
|
reiern70
left a comment
There was a problem hiding this comment.
Thanks, Emond. I read it and ran it merged onto current master: the tests of wicket-core, wicket-core-tests and wicket-native-websocket-core, and the QUnit suites for both engines, pass. It stands on its own well outside Islands. addData is a cleaner way to hand values to client-side code than appendJavaScript plus an escaping helper.
What I checked and agree with:
- The data steps run after the header contributions, components and evaluations of the same response. A library that a header item in the same response loads is therefore ready when its data arrives, and the order doesn't depend on where
<data>sits in the XML. - A
]]>in a value is split across CDATA sections, andWicket.DOM.textjoins them again. Your QUnit response covers that. - Data can be added until the components are written (from
renderHeadoronBeforeRespond), andisEmpty()counts it, so a web socket push that carries only data is still sent. - Abstract methods rather than defaults that silently drop the data: agreed, and fine for 12.
Points:
-
"Exactly as given" isn't quite true, and some values break the whole response. The value travels in XML, so the browser's XML parser applies two rules to it:
- Line breaks are normalized:
\r\nand a lone\rarrive as\n. - Characters that XML 1.0 does not allow make the response unparsable: U+0000 to U+0008, U+000B, U+000C, U+000E to U+001F, U+FFFE, U+FFFF and unpaired surrogates.
I checked both in Chromium with
DOMParseron a<data>element like the onewriteDatawrites."a\r\nb"came back as"a\nb"."a\u000Bb"gave a parser error; a vertical tab is common in text pasted from Word. On a parser error the whole call fails with "Error while parsing response", so none of the components in that response are replaced either.Components and scripts have the same limits today, but a data value is much more likely to be raw user text. JSON is safe, because encoders escape control characters. I'd suggest:
addDatarejects a value with characters XML cannot carry, with anIllegalArgumentExceptionthat names the entry. The error then shows up on the server, where it was made, rather than as a parse error in the browser.- The Javadoc of
IPartialPageRequestHandler#addDatareplaces "exactly as given": line breaks arrive as\n, and arbitrary text should be sent in an encoding such as JSON.
- Line breaks are normalized:
-
Conflicts with master.
wicket-ajax.js,wicket-ajax-jquery.jsandajax_6.adocconflict with thequeuedanddroppedtopics from #1997; keep both sides. Inmigration-to-12.md, master no longer has thePageParameters.hashCode()section that your hunk sits under, so the data section goes in as a section of its own. I resolved the conflicts locally for the test run, and the diff against master stayed the same 308 lines. -
Reference guide (nit). The
'/ajax/call/data'entry mentions onlyAjaxRequestTarget. As the Javadoc does, it could also mention web socket pushes, whereattrsis an empty object.
With 1 and 2 addressed, this looks good to me.
The topic constants and the guide's list of topics keep both the data topic and the queued and dropped topics from #1997. Master no longer has the PageParameters.hashCode() section the migration section sat under, so the data section is now a section of its own at the end of the guide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A data entry travels in a CDATA section of the XML Ajax response, so the browser's XML parser applies its rules to it. Line breaks are normalized, \r\n and a lone \r arriving as \n, and characters that XML 1.0 does not allow, such as a vertical tab in text pasted from a word processor, make the whole response unparsable. The call then failed in the browser with "Error while parsing response", and none of the components in that response were replaced either. The Javadoc nevertheless promised the value would arrive exactly as given. addData now rejects a name or value containing such a character with an IllegalArgumentException naming the entry, so the error shows up on the server, where it was made. The Javadoc and the reference guide say that line breaks arrive as \n and that arbitrary text should be sent in an encoding such as JSON, whose encoders escape these characters. The guide entry also mentions web socket pushes, whose subscribers receive an empty attrs object. For components, Wicket's answer to the same characters remains the opt-in XmlCleaningResponseFilter, which strips them. A data value that silently loses characters is worse than an error, so data entries are rejected instead, and the filter never finds anything to strip in them. The character test moves to Strings.isValidXmlChar, which the filter now uses as well. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, Ernesto, for the thorough check.
A full |
Brings in the review fixes of #1907, rejecting data entries that XML cannot carry, and current master. The poms keep the modules and the managed dependencies of both sides in sorted order: wicket-dbsc from master next to wicket-islands, and the examples depend on wicket-dbsc and wicket-resumable-upload as well. Selenium takes master's newer version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
reiern70
left a comment
There was a problem hiding this comment.
Thanks, Emond. All three points are addressed, and rejecting on the server is the right call.
One nit on wording I suggested myself: JSON encoders do not escape all of these characters. Jackson 3.3 escapes the control characters, but writes U+FFFE, U+FFFF and unpaired surrogates as they are unless JsonWriteFeature.ESCAPE_NON_ASCII is on. The Javadoc and the guide could say that such an encoder has to escape these too.
This has a consequence in Islands, see my comment on #1834.
reiern70
left a comment
There was a problem hiding this comment.
All three points are addressed, thanks Emond. The nit on the wording about JSON encoders from my last comment is not a blocker.
The Javadoc of addData and the reference guide said that JSON encoders escape the characters XML cannot carry. They escape the control characters, but not all of them escape the noncharacters U+FFFE and U+FFFF or unpaired surrogates: Jackson writes those as they are unless it is told to escape non-ASCII characters. Such a value is then rejected by addData. Both now list these characters and say the encoder has to escape them too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks, Ernesto. The wording is fixed in 123a529. The Javadoc of |
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