Hi,
On Mon, Mar 16, 2020 at 10:56 AM Tobias Gierke <[email protected]>
wrote:
> Hi,
>
> We have a large (>350 pages) Wicket application that is currently using
> server-side charts (JFreeChart) but are looking for a smooth way to
> migrate to client-side D3.js charts. Ideally we would like to be able to
> do something like this:
>
> ChartImage img = ...
> img.add( new JSONBehaviour() {
>
> public String getChartDataJSON() {
> return ....;
> }
> } ;
>
> The behaviour would write a callback URL as an attribute to the markup.
> The callback URL would be an endpoint that returns a plain AJAX response
> (the dataset to render for this chart). The tricky part is dynamically
> registering a callback URL that is scoped to the life-cycle of the
> component and returns a plain AJAX response. Since something similar
> must already be happening for Wickert AJAX behaviours, is there a way I
> can piggy-back on the same Wicket-internal mechanism to dynamically
> register my own AJAX endpoint ?
>
You can do something like this:
AbstractDefaultAjaxBehavior beh = new AbstractDefaultAjaxBehavior() {
@Override public void onRequest(AjaxRequestTarget target) { ... }
}
component.add(beh);
component.add(AttributeModifier.replace("data-my-special-attribute",
beh.getCallbackUrl()));
and then in your JS code: var url =
$('#compontId').data('my-special-attribute');
>
> Thanks in advance,
> Tobias
>
>
>