API / Apache Wicket Interview questions
How do you integrate WebSockets into a Wicket application?
Wicket ships native WebSocket support through the wicket-native-websocket module, which lets server-pushed events update a page's components without the client having to poll or initiate every exchange itself, unlike the request-driven model regular AJAX components use.
- Add the native WebSocket module as a dependency and register the appropriate
WebSocketBehavior(or a subclass likeWebSocketPushBroadcasterdepending on the exact use case) on the component that needs push updates. - Implement message handling by overriding methods like
onMessage()oronConnect()on the behavior, similar in spirit to overridingonClick()on a Link. - Push updates from server-side code (say, a background job or another user's action) using a broadcaster that finds the target page's WebSocket connection and sends it an update, which the behavior then turns into a partial component re-render, much like an AJAX response.
- Fall back gracefully for clients or proxies that don't support WebSockets, since not every deployment environment guarantees a persistent connection stays open.
The practical use case is exactly what you'd expect — live notifications, real-time dashboards, chat features — anywhere the update needs to originate from the server without waiting for the browser to ask first, which a purely AJAX-driven, click-triggered model can't do on its own.
More Related questions...