GeeCON Prague 2014*
The moose likes JSF and the fly likes Refreshing Data Automatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "Refreshing Data Automatically" Watch "Refreshing Data Automatically" New topic
Author

Refreshing Data Automatically

David Salaete
Greenhorn

Joined: Aug 27, 2008
Posts: 19
Hi all,

I have a JSF page containing a richFaces DataTable.

Well, I need to refresh it every X seconds.

I can do it using Javascript, but I have to refresh all the page, so I obtain an ugly screen blinking, and that�s slow.

Is there any way to refresh only the data table (using AJAX, I suppose, but, how?? ) I can�t find any tutorial or help..!

Thanks in advance,

David.


There are 10 types of people: Those who understand binary code and those who don�t.
Duc Vo
Ranch Hand

Joined: Nov 20, 2008
Posts: 254
Originally posted by David Salaete:
Hi all,

I have a JSF page containing a richFaces DataTable.

Well, I need to refresh it every X seconds.

I can do it using Javascript, but I have to refresh all the page, so I obtain an ugly screen blinking, and that�s slow.

Is there any way to refresh only the data table (using AJAX, I suppose, but, how?? ) I can�t find any tutorial or help..!

Thanks in advance,

David.

This demo should help you. It's about a4j:poll control.


“Everything should be as simple as it is, but not simpler.” Albert Einstein
Dmitriy Kastikovich
Greenhorn

Joined: Jun 29, 2008
Posts: 23
hello!

I see this example - that is a solution. But how about the variant of checking the new data in bean and automatically refresh dataTable, when new data came ? Can anyone provide an example?

Seems, it is not possible.
[ December 23, 2008: Message edited by: Dmitriy Kastikovich ]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

The JBoss RichFaces JSF tag library allow you to define regions and/or components that are refreshed according to your desires. It's done using AJAX, but most of the ugly JavaScript is handled for you. About all you'd need is some sort of little timer script that would fire a data update request when you want the data display to be refreshed.

This not only cuts down on the visual annoyances. It also means that only the changes to the view need be sent, saving bandwidth and making it possible to service more simultaneous users.


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

Joined: Jun 29, 2008
Posts: 23
ok, its rather clean I think.

So, I cant find how to implement this: JScript timer calls 'reRender' on InputHidden to get a new data from bean. So then I want to get value from component and if it is TRUE, refresh table.

Can you help me on how to reRender(refresh) a component from a JavaScript?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16101
    
  21

reRender isn't a command, it's an indicator. You need to fire an action in order to get the item(s) to refresh.

This makes sense because HTTP isn't a "push" protocol. It can only return data when someone or something asks for it. And in JSF, that means a response to an action request. Your action processor would normally update the model.

Here's how a commandButton does it:



To make this work on periodic polling from a JavaScript timer, you would need to make the script "press the button".

Actually, RichFaces has some more direct options to initiate AJAX actions in the a4j tags.
 
GeeCON Prague 2014
 
subject: Refreshing Data Automatically