I want to display a popup window whenever an event (say some timeout occurs at server) occurs. For the popup window I am using jQuery in JSF pages (JSF 2.0). How do I call a jQuery function from a service method of a JSF ManagedBean?
Actually it's like reverse of AJAX instead of client making periodic calls to the server. I want the server to notify the client whenever some event occurs. Not all the users will have notifications all the time. I want to reduce the network calls. The server tells the client from his side that "Mr. X, this is a notification for you ".
Instead of trying to tie Java and jQuery together, simply define your jQuery call such that, unless it gets a response within a certain time frame, it will display a "server is being slow" message, or some other appropriate alert.
In other words (example):
- You do an ajax call, and while you're waiting you're displaying "Loading..." or some message
- By default, if the ajax call doesn't receive a response within a defined timeout (say 5 seconds), it will automatically display, "Sorry, we're still waiting...", or whatever is appropriate for your app
- If the ajax call does get a response in time, the user will simply never see the "Sorry, we're still waiting..." message, because the page will be updated with the results