so in it's simplest form my page would look like this:

    final MarkupContainer anotherComponent = add(new
Label("anotherComponent", "Updating should be pushed"));

    anotherComponent.add(
            new WebSocketBehavior() {
                @Override
                protected void onPush(WebSocketRequestHandler handler,
IWebSocketPushMessage message) {
                    super.onPush(handler, message);
                    handler.add(anotherComponent);
                }


            });


}


And will get anotherComponent refreshed with every WebsocketPushes..
It would be nice if there were a simple filter or way to determine if
the websocket push were relevant for the actually push..

The current implementation does feel a little lowlevel..


On Thu, Aug 17, 2017 at 9:36 AM, nino martinez wael <
[email protected]> wrote:

> Thanks Martin! Yes specially 2.2.x will probably be used a lot.. Would be
> great to have an sample for it.. I'll conjure one up for pax wicket..
>
> On Thu, Aug 17, 2017 at 9:29 AM, Martin Grigorov <
> [email protected]> wrote:
>
>> WebSocketBehavior has only callbacks. They have IPartialPageUpdateHandler
>> as parameter (this is the base interface for AjaxRequestTarget and
>> IWebSocketRequestHandler) which you can use to add components.
>>
>> There are two use cases:
>>
>> 1) the browser sends a message
>> WebSocketBehavior#onMessage(Text|Binary, IPartialPageUpdateHandler) is
>> called and you can react on this message
>>
>> 2) the server pushes a message
>>
>> 2.1) simple case: broadcast plain text or byte[]
>>
>> WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(
>> application);
>> webSocketSettings.getConnectionRegistry().getConnection(app[, sessionId,
>> pageIdKey]).sendMessage( text | binary );
>>
>> 2.2) more complex case: update Wicket components
>>
>> here you need to broadcast IWebSocketPushMessage - this is a
>> specialization
>> of IWebSocketMessage that is used when you need to push from the server to
>> the client
>>
>> This code could be in any application service class:
>>
>> WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(
>> application);
>> WebSocketPushBroadcaster broadcaster = new WebSocketPushBroadcaster(
>> webSocketSettings.getConnectionRegistry());
>>
>> 2.2.1) to all connections:
>> broadcaster.broadcastAll(application, message);
>>
>> 2.2.2) to specific client
>> ConnectedMessage wsMessage = new ConnectedMessage(application, sessionId,
>> pageIdKey);
>> broadcaster.broadcast(wsMessage, message);
>>
>>
>> Broadcasting IWebSocketPushMessage will call WebSocketBehavior#onPush()
>> where you can update any components
>>
>> We should add this to the guide!
>>
>> Martin
>>
>> On Aug 17, 2017 09:28, "nino martinez wael" <[email protected]
>> >
>> wrote:
>>
>> > But how do I then refresh the target from serverside? WebSocketBehavior
>> > does not have an method that lets me get a target?
>> >
>> > On Thu, Aug 17, 2017 at 7:45 AM, Martin Grigorov <
>> > [email protected]>
>> > wrote:
>> >
>> > > Yes.
>> > > The API is the same.
>> > >
>> > > On Aug 17, 2017 08:44, "nino martinez wael" <
>> > [email protected]>
>> > > wrote:
>> > >
>> > > > is there way to repaint an component like with ajax targets
>> > > > (target.add(component))?
>> > > >
>> > > > On Wed, Aug 16, 2017 at 1:57 PM, nino martinez wael <
>> > > > [email protected]> wrote:
>> > > >
>> > > > > I'snt there something more simple?
>> > > > >
>> > > > > On Wed, Aug 16, 2017 at 1:54 PM, Martin Grigorov <
>> > [email protected]
>> > > >
>> > > > > wrote:
>> > > > >
>> > > > >> Use the examples as inspiration:
>> > > > >>
>> > > > >> http://examples8x.wicket.apache.org/websockets/
>> > > > >> https://github.com/apache/wicket/tree/master/wicket-examples
>> > > > >> /src/main/java/org/apache/wicket/examples/websocket
>> > > > >>
>> > > > >> Martin Grigorov
>> > > > >> Wicket Training and Consulting
>> > > > >> https://twitter.com/mtgrigorov
>> > > > >>
>> > > > >> On Wed, Aug 16, 2017 at 2:52 PM, nino martinez wael <
>> > > > >> [email protected]> wrote:
>> > > > >>
>> > > > >> > Hi
>> > > > >> >
>> > > > >> > I am looking into Wicket 8 and websockets using pax wicket, in
>> my
>> > > case
>> > > > >> I am
>> > > > >> > using jetty 9.3.14. I want to do a simple websocket sample..
>> > > > >> >
>> > > > >> > However I cannot find something as simple as
>> > > > >> > a AjaxSelfUpdatingTimerBehavior as an websocket behavior..
>> > > > >> >
>> > > > >> > So whats the simplest way todo a websocket example that shows
>> some
>> > > > >> change
>> > > > >> > at clientside?
>> > > > >> >
>> > > > >> > --
>> > > > >> > Best regards / Med venlig hilsen
>> > > > >> > Nino Martinez
>> > > > >> >
>> > > > >>
>> > > > >
>> > > > >
>> > > > >
>> > > > > --
>> > > > > Best regards / Med venlig hilsen
>> > > > > Nino Martinez
>> > > > >
>> > > >
>> > > >
>> > > >
>> > > > --
>> > > > Best regards / Med venlig hilsen
>> > > > Nino Martinez
>> > > >
>> > >
>> >
>> >
>> >
>> > --
>> > Best regards / Med venlig hilsen
>> > Nino Martinez
>> >
>>
>
>
>
> --
> Best regards / Med venlig hilsen
> Nino Martinez
>



-- 
Best regards / Med venlig hilsen
Nino Martinez

Reply via email to