0

Hey all, I'm pretty new to jsf so if this is a poor question then I apologize. I'm currently working on a school project where I need to access a database through a web service to get some basic application data. I have a class that accesses this data through a method and then returns the newest results from the database.

What I want to do is to either spawn a thread that calls the update method on the database. The run method looks similar to this, where i get my application bean and then I call the refresh method on it.

theFacesContext = FacesContext.getCurrentInstance();
ApplicationBean app = (ApplicationBean)theFacesContext.getELContext().getELResolver().getValue(theFacesContext.getELContext(), null, applicationbean);
app.getDBValues();

The thread would then loop based on a variable that would be set to false when the application bean was destroyed. My error is that the thread looses the facescontext. I've seen some posts where people say something allong the lines that you have to keep the thread in a request, but I'm not sure what that means. Any suggestions would be extremely helpful.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140

2 Answers2

1

If you want to display actual data, you should use polling or server-side push. There are a lot of ajax components that may help. Look at
PrimeFaces poll component
RichFaces push
RichFaces poll
ICEfaces

George Suaridze
  • 509
  • 1
  • 8
  • 16
0

It is indeed true that FacesContext is not available in a new thread. This is because it is stored in a ThreadLocal, and is initiated per request.

You can get your desired bean and pass it to the new thread, so that you no longer rely on the faces context there.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140