views:

79

answers:

5

When we create a JSF page, a client request allows generation of HTML dynamically using a combination of java code and HTML. Can we introduce hooks in the HTML page using JSF framework, that allow server to update the HTML page based on events occurring at the server?

A: 

You can have a look at Seam (see this article for a discussion to use Seam with JSF and AJAX).

When I used Seam the last time, it was pretty slow, though. You may want to create your own JSF component that generates JavaScript (for example using jQuery as explained in this article).

Aaron Digulla
A: 

IceFaces has IcePush and PrimeFaces has p:push.

According to other's experiences, the IceFaces one seems much easier to setup and run. I don't have experience with it, but my experience with the PrimeFaces one was not so good, because Atmosphere, which it is using under the covers, isn't very pretty to setup. It's not clearly documented (comes along with a bunch of JAR's whose composition depends on the servletcontainer used, it was not immediately clear which ones I should include/omit for Tomcat and Glassfish) and it has some problems at certain serverconfigs (couldn't get it ever to run on Tomcat). That was unfortunate, because Atmosphere looks pretty awesome on paper. Things may have changed/improved since then.

Alternatively, you can also use polling instead of pushing. Pretty much every ajaxical JSF component library has such a poll component which is relatively easy to setup.

BalusC
In stackoverflow, when we are editing a question and in the meanwhile if someone else edits the question, we get a message on our editing page. Is that implemented using polling or server side push?
iamrohitbanga
Using polling. Check the source and install [Firebug](http://getfirebug.com) to track XHR (Ajax) requests.
BalusC
A: 

Simplest for you can be introduction of ajax4jsf library's "poll" component: https://ajax4jsf.dev.java.net/nonav/documentation/ajax-documentation/entire.html#d0e1955

It will not need application reconfiguration and big changes in JSF page (only adding a4j:poll component)

It worked very good in couple of my projects.

Andriy Sholokh
A: 

You can't push anything. You need to poll data from your client code. Web components create the page and then terminates. It is not intended to stay running looking for some kind of new data to push it to the client.

Maybe your application isn't easy to write as a web app. I would try an applet connected to a server port to receive new events maybe using JMS. See this article http://it.toolbox.com/blogs/enterprise-web-solutions/applet-and-jms-using-glassfish-and-jdk-6-34816

jorgeu
A: 

If you need fully-featured Comet updates (reverse Ajax) and so on, then its worth taking a look at the DWR library.

scottw