papegaaij opened a new pull request, #1907:
URL: https://github.com/apache/wicket/pull/1907

   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](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to