I'm currently checking out the Tomcat 7 websockets and got them working smoothly. But I have a design question about the different contexts: The websocket handling is done in a separate servlet context from where I don't have access to the current View context of the page bean. Is there a way to access the data on the view scoped bean related to the page that initiated the websocket message? Or am I following a wrong design pattern? I couldn't find any examples on the web that illustrate this point.
In any event, if you have other servlets/JSPs active while a websocket is in play, they can share data via the HttpSession and/or Application scope objects.
I would not include the websocket code directly in a servlet, JSP or GUI interface objects (Model, View definitions) for the same reason that I don't include complex business functions there. It's cleaner to have one function/one module.
An IDE is no substitute for an Intelligent Developer.
Thanks for your answer. Indeed, I forgot to mention I'm talking JSF. Could you please elaborate a bit more about how to use session or application objects to communicate? For instance, if a message arrives on the websocket, the socket's servlet callback "MessageInbound.onTextMessage(CharBuffer)" is called. You suggest not to include any business login in there. Sounds good, but then allow me to rephrase my original question: What's then the proper way to activate the business logic in the view scoped bean? Or: How to pass messages asynchronoulsy from one context (socket servlet) to another (view bean), v.v.?