Trigger repainting a wicket component via push message
websocket, wicket
Solution
Check https://github.com/martin-g/blogs/tree/master/wicket6-websocket-broadcast. This example shows exactly what you want.
https://github.com/martin-g/blogs/blob/master/wicket6-websocket-broadcast/src/main/java/com/wicketinaction/TimestamperTask.java#L27
https://github.com/martin-g/blogs/blob/master/wicket6-websocket-broadcast/src/main/java/com/wicketinaction/FeedPage.java#L78
Problem
I understand the concept of repainting wicket components using `add(Component)` method of `AjaxRequestTarget` - but I can only use this method when the client triggers some ajax event. But I have to repaint a component without any user interaction involved, so I can't use that. Next step was to discover `WebSocketBehavior` and it's associated method `onMessage()` - this message again gets a parameter of type `WebSocketRequestHandler` (which extends `AjaxRequestTarget`) to that I could add my to-be-repainted-component. But again this method seems only to be called when the client sends a websocket-message to the server. Lastly I discovered I can trigger asynchronous messages from server side by opening an `IWebSocketConnection`. Wicketinaction suggests in this blog post (http://wicketinaction.com/2012/07/wicket-6-native-websockets/) the following code lines: ``` IWebSocketConnectionRegistry registry = new SimpleWebSocketConnectionRegistry(); Application application = Application.get(wsApplicationName); IWebSocketConnection wsConnection = registry.getConnection(application, wsSessionId, wsPageId); if (wsConnection != null && wsConnection.isOpen()) { try { wsConnection.sendMessage("test"); } catch (IOException e) {} } ``` wsApplication, wsSessionId and wsPageId are obtained in the `onConnect` method of the WebSocketBehavior. In general this approach works - I can send my test message to the client and it receives exactly this text. But I can't find a way how to trigger a component repaint with this method. Any suggestions on this would be appreciated - or am I completely wrong in the end?