aspose file tools*
The moose likes JSF and the fly likes JSF page refresh triggered from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF page refresh triggered from database" Watch "JSF page refresh triggered from database" New topic
Author

JSF page refresh triggered from database

nikola petanjak
Greenhorn

Joined: Apr 01, 2011
Posts: 19
Hello everyone,

can someone give me clue how to refresh JSF 1.2 page when database table gets updated? Alternative is also, that onMessage method in message bean trigger page refresh.

Thanks in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16014
    
  20

HTTP is a request/response protocol and JSF is built on top of HTTP. What request/response means is that HTTP servers cannot output data (responses) unless a request was made first. There is a strict 1:1 correspondence between requests and responses, and no request may have multiple responses, nor may the server send unsolicited or asynchronous responses.

So in order to get a page refreshed when a database changes, you must design the webpage to be self-requesting. There's an HTML META tag that can cause the user's browser to send a request after a defined time interval has expired. AJAX can do that as well, but you said "page refresh", not "page update", so I'm going for the simpler solution here.

Likewise, the JSF server-side logic is invoked only on request, so a database cannot simply post updates to the data, the JSF logic has to issue a query to the database when the request has been made. Whether it's easier and more efficient to simply make the same SQL request over and over or attempt something fancier depends on your overall app and database infrastructures. Often the overhead for repeated queries is pretty low, since the unchanged data would be in cache either on the DBMS server, in the webapp, or both places.


Customer surveys are for companies who didn't pay proper attention to begin with.
nikola petanjak
Greenhorn

Joined: Apr 01, 2011
Posts: 19
Hi Tim, and thank you for your reply.

The problem is, our customer would like fancy solution. I would like to know is it possible to do that kind of refreshing/updating?
In my actual problem, i'd need to update few tables on page after new database update. Can i use ajax with jsf1.2?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16014
    
  20

You can use AJAX with JSF 1.x, yes. Although it's not an integral part of JSF like it is in JSF2, there are several ways to do AJAX in JSF1.

You can do brute-force JavaScript AJAX, if you like to punish yourself.

You can use a system like jQuery to handle the AJAX.

You can use an AJAX-aware extension tag library. RichFaces and IceFaces are 2 popular ones that provide AJAX support that works under JSF 1.1 and 1.2.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF page refresh triggered from database