Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Refreshing Data Automatically

 
David Carrascal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dmitriy Kastikovich
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dmitriy Kastikovich
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic