Getting access to AjaxRequestTarget

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting access to AjaxRequestTarget

Roman Sery
Hi, I have a question about getting access to the AjaxRequestTarget outside
the context of an ajax request.

What I'm trying to do is send some javascript from the server to the
browser from a different thread where RequestCycle.get() is not available.
From within a WebPage,  Im using Redis pub/sub channels, to subscribe to a
channel on page load, and when there are publications to the channel, I
need to send some JS to the browser.

psudeo code:

WebPage() {
start listening to channel a123, callback Function = onMsgPublished
}

onMsgPublished(){
     //do something like this
     target.appendjavascript("alert('test')");
}

Any ideas or perhaps some other way to accomplish this?
I'm using wicket 8.4.  Thanks for any help!
Reply | Threaded
Open this post in threaded view
|

Re: Getting access to AjaxRequestTarget

Martin Grigorov-4
Hi,

You can't do this the way you described it because Ajax is initiated by the
browser.

I can propose you three options:

1) use Ajax polling
Store the messages in some data structure in the page/panel and with the
help of AbstractAjaxTimerBehavior render the collected messages

2) WebSocket
Add WebSocketBehavior (wicket-native-websocket-javax module) and publish
IWebSocketPushMessage when you receive one from Redis.
This way it will be real time instead of batching

3) Use Server Side Events - it is similar to web sockets but
unidirectional.
You can use wicketstuff-html5 library. It has SSE support.

I would recommend you 2)

Cheers,
Martin


On Sat, Jun 8, 2019, 03:22 Roman Sery <[hidden email]> wrote:

> Hi, I have a question about getting access to the AjaxRequestTarget outside
> the context of an ajax request.
>
> What I'm trying to do is send some javascript from the server to the
> browser from a different thread where RequestCycle.get() is not available.
> From within a WebPage,  Im using Redis pub/sub channels, to subscribe to a
> channel on page load, and when there are publications to the channel, I
> need to send some JS to the browser.
>
> psudeo code:
>
> WebPage() {
> start listening to channel a123, callback Function = onMsgPublished
> }
>
> onMsgPublished(){
>      //do something like this
>      target.appendjavascript("alert('test')");
> }
>
> Any ideas or perhaps some other way to accomplish this?
> I'm using wicket 8.4.  Thanks for any help!
>