I am calling a thread from a backing bean that makes many db activities. I want to add message to the context, but until i get to the end of the run() method the context is already released. How can i add message to context inside run() method of thread , without depending on the bean?
2 Answers
Yes.. you can do this with ajax push... You can use prime faces or whatever you want to do the pushing...
You should make a bean for notifications.. and whenever you want to notify on the client (as you like) announce that bean somehow... think about it :)
In this way you can announce the client after 30 minutes that what he wanted is done...
In worst case scenario you can use "setInterval" function in javascript.. to periodically check a servlet for messages...
Here is a tutorial for commet..
More details about comet here
(Yes.. with ajax push is a pretty long way.. - if you want to do it by yourself)
cheers.

- 2,126
- 3
- 25
- 47
-
in my web we don't use prime or ice .is there any other option you know? – OshikawaL Feb 20 '12 at 10:26
-
you can use jQuery or something you want (even pure javascript - I suggest jQuery to everybody because is crossbrowser).. and do by yourself an ajax push... I think you can do this using a servlet.. Read this: http://en.wikipedia.org/wiki/Comet_(programming) but I suggest you use primefaces only for the page you need :) – Alex Feb 20 '12 at 10:31
-
maybe you can link me an example because i don't know it very well? – OshikawaL Feb 20 '12 at 10:35
-
here is an example of push: http://www.primefaces.org/showcase/push/chat.jsf ... I will edit my post if I find an ajax push tutorial – Alex Feb 20 '12 at 10:40
-
my opinion is that you should use primefaces.. only for this scenario.. :) – Alex Feb 20 '12 at 10:53
-
RichFaces has ajax push support, too: RichFaces 3.3 (JSF 1.2): http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_push.html RichFaces 4 (JSF 2): http://in.relation.to/Bloggers/GettingStartedWithRichFaces40Push – Jeremiah Orr Feb 20 '12 at 16:24
-
Yes... You can use any implementation... – Alex Feb 21 '12 at 17:10
The faces context instance is bound to the thread servicing the current request via a ThreadLocal. You may try retrieving the FacesContext instance and passing it as a variable to the thread before starting it.

- 14,532
- 10
- 61
- 73
-
-
i'm assuming you are starting your threads in the invoke application phase? if so, do you wait for them to finish before returning a outcome string? – Abbas Gadhia Feb 20 '12 at 10:34
-