2

We have a large application developed with JavaEE (primefaces, wildfly, Websocket). The idea behind the important functionality of our application is that if two or more users are online at same time then they can see each others status.

e.g. If 'Maik' and 'Andre' are online then Maik can see Andre's online status and Andre sees Maik's status.

We uses Websocket(Server endpoint, Javascript Websocket API at client sides).

Clients send their user-ids (UUID) over secure websocket to server, server saves them in a Hashmap(key: page-id where users are currently logged, value: user-id). Server returns a json string to clients and clients then send the string to backing bean with a parameterized RemoteCommand.

ws.onmessage = function(e) {
     console.log("received msg: " + e.data);
        showOnlineUsers([ {
            name : 'jsonString',
            value : e.data
        } ]);
    }

RemoteCommand in xhtml page is used as:

    <p:remoteCommand name="showOnlineUsers"
        action="#{bean.showOnlineUsers()}"
        process="@form" update="OnlineUsersFormId:onlineUserId" />

The RemoteCommand calls a backing bean function - showOnlineUSers().

String jsonString = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("jsonString"); 

 // Logic to extract jsonSting and generate a List of users.
 // Set the users list for XHTML component.

setUsersList(list);

After calling the backing bean function, RemoteCommand updates a component "OnlineUsersFormId:onlineUserId" in XHTML page. The exact jsf component in the page is as below:-

<h:form id="OnlineUsersFormId">
    <h:panelGroup id="onlineUserId">
        <ui:repeat var="user" value="#{bean.getUsersList()}">
            #{user.getUserName()}
        </ui:repeat>
    </h:panelGroup>
</h:form>                                                   

Problem: Logic works fine, but after working some time it suddenly stops workig when a user(Maik) leaves the page but his name is not being removed from other user's (Andre) page (Although the Server tells him to remove Maik's name- it also works fine only for some time). Our gut feeling says that something with "updating the component" in remoteCommand works abnormal.

Any help would be appreciated.

Best regards, Tahir

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Tahir
  • 29
  • 3
  • The server does not tell the page to remove the name, it tells it to rerender the panelGroup. Investigate your gut feeling. What **does** the response to the remote command look like? – Kukeltje Jun 07 '16 at 15:10
  • Actually server removes the offline-user from list and sends only the online user-ids to clients (I did not post that part because it was trivial). When RemoteCommand updates a component on page, it supposes to retrieve only online users from backing bean. So far it does as it supposed to. – Tahir Jun 07 '16 at 15:30
  • Problem occurs after a while when **first** user leaves the page and come back to the same page (till here works fine) and then the second user leaves the page but first user still sees **second user** as online. I could say it only works one way, it doesn't matter how many times we repeat the steps of leaving a page and coming back to it for a specific **user**, it works, as soon as we changes the routine and **second** user leaves the page, then problem occurs. – Tahir Jun 07 '16 at 15:30

0 Answers0