Reputation: 2853
I am trying to push data from the server to the client without client(browser) requesting an update.
My application is based on JSF2.0 (with JSPs) and RF3.3 on JBoss server.
I have gone through numerous links to try and understand how can i achieve it. Terms like long polling,piggybacking,server side polling are all understood by me.
I guess that it can be done using COMET with atmosphere(i think it is not applicable for JBoss) but I am not sure of the same. Major problem is I can hardly think of a starting point as I failed to get any kind of code tutorial or a demo code doing the same on the net.
Morever the starting point itself is not very clear as to from where should I start and what all I will be needing on the way to achieve the desired functionality.
Can anyone guide me on this.I am pretty lost on this topic.
The general use case scenario is that user is browsing some web page inside my application and suddenly I need to raise a notification or update a value on the page without user firing a request for the same.
Upvotes: 1
Views: 1235
Reputation: 1049
RF4.2 makes this very simple indeed but I find that polling through jQuery to a special servlet works just as well if you don't want RichFaces.
// Javascript part
jQuery.ajax({
url : "/poll?sessionKey=" + sessionKey,
dataType : "text",
success : function(data) {
// ... Do your thing to depending on the contents of data.
},
error : function(xhr, ajaxOptions, thrownError) {
// ... Oops, something went wrong.
}
});
// Server part
@WebServlet(urlPatterns = "/poll")
public class pollServlet implements Servlet {
}
The polling is very cheap and you could do it every couple of seconds without much impact. One additional benefit is that you can monitor if the browser window is still open.
Upvotes: 0
Reputation: 3657
If you are open to using RF 4.0.X, there is an example that shows how to use ajax push. You can find an example here
http://anonsvn.jboss.org/repos/richfaces/branches/4.0.0.CR1/examples/push-demo/src/main/webapp/chat.xhtml
http://anonsvn.jboss.org/repos/richfaces/branches/4.0.0.CR1/examples/
If you have to stick to RF 3.3, you can find relevant examples here as a starting point
http://anonsvn.jboss.org/repos/richfaces/branches/community/3.3.X/samples/
Upvotes: 1