0

I want to refresh an XHTML page (jsf) or part of this page, when a variable in a manageBean changes the value.

The problem is:

I have a JavaBean, which receives data from a webService. This data changes regularly. when a variable changes value, I want to display it in the IHM page.

I want that my application detects these changes and refresh the page automatically.

Thank you.

Marko
  • 20,385
  • 13
  • 48
  • 64
Karim Oukara
  • 2,638
  • 8
  • 38
  • 51
  • 1
    IMHO it's not the best way to refresh a view out of the backend. Most of those cases can be avoided by doing a partial request triggered from the view. I would like to give you a hand but for doing so I'll need to see some of your code and maybe a detailed explanation of what you want to do. Cheers! – SimonSez Sep 26 '12 at 15:36
  • There are many ways to achieve this, depending on the concrete functional requirement and the available/used libraries. This information is however completely missing in your question. Please edit and improve your question to elaborate more about them. – BalusC Sep 26 '12 at 15:45
  • the problem is : I have a JavaBean, which receives data from a webService. this data changes regularly. when a variable changes value, I want to display it in the IHM page. I want that my application detects these changes and refresh the page automatiquely – Karim Oukara Sep 26 '12 at 15:52
  • There is no push in html, so you need to let the page check every x time. Call the bean and let the bean call the webservice to see if teh value has changed. – roel Sep 26 '12 at 16:10
  • @roel That's not quite true, look at [Comet](http://cometd.org/) (and probably a bunch of other tools) for instance. Server-to-client communication is a very important problem for Web 2.0 apps and it's not exactly being ignored. (That said, Comet isn't a JSF technology and it might not be particularly convenient to integrate it. It depends on the OP's requirements if it's the right solution compared to long polling.) – millimoose Sep 26 '12 at 17:22
  • @roel: there's also web sockets (which PrimeFaces Push is using). – BalusC Sep 26 '12 at 20:33
  • thx for your responses ! to summarize. I understand that the communication `server> IHM` is impossible. or IHM must ask the changes ! – Karim Oukara Sep 27 '12 at 14:20

3 Answers3

2

Use ajax polling. Demos:

Note that RichFaces 3.3 works with JSF 1.2 and JSF 2, RichFaces 4.x and PrimeFaces 3.x works with JSF 2.x

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Alvin Pradeep
  • 618
  • 4
  • 13
1

One quick way would be to use a third-party library like PrimeFaces

This library includes a component called poll with wich you can check your backend in a preset interval and update your view component(s) on changes.
Check out the link to see an easy example.

Hope this helpes. Have Fun!

Nicola Isotta
  • 202
  • 3
  • 10
SimonSez
  • 7,399
  • 1
  • 30
  • 35
  • thx for your responses ! to summarize. I understand that the communication `server> IHM` is impossible. or IHM must ask the changes ! – Karim Oukara Sep 27 '12 at 14:19
  • It is hardly possible/bad practice. The request to show/update the view has already been sent, therefore there is no communication between view and backend unless you trigger it by an action component like *button* or *poll*. Cheers – SimonSez Sep 28 '12 at 07:36
1

You can use poll option of ajax in jsf like

<a4j:poll interval="timeinms" reRender="jsfcomponent"> </a4j:poll>
Dipul Patel
  • 187
  • 6