The application scoped bean's events will be visible to all session scoped observers, but session scoped events aren't visible in other sessions.
I use this construction in combination with ajax poll to inform all session about changes in the model (database).
I have tried it and only the component (session scoped) from the session that initiated the change receives the event raised by the application scoped bean.
How can I produce a model with an application scoped bean that
broadscastsevents to all the instances of the session scoped bean ?
Is this possible using Events ?
Thanks in advance,
First thanks for your answer. This exactly what I expect but it doesn't work in my app...
Let me be more precise describing my app and the problem I have:
I have an application bean that holds a cached table (I didn't choose that design, I am expanding an existing webapp to use seam and I have to do with that, I can't use JPA entities). Lets call this bean the
I have 2 session beans:
One session beans that commits data to the DB via the appCacheBean, lets call it
commiterBean. In the appCacheBean, at the end of the commit, if it is successfull, I do a Events.raiseEvent(
The other session bean that @Observes the
dataInsertedevent and updates the user session UI. Lets call it
The problem I have is the following;
I have 2 users (User1 and user2) connected (therefore 2 sessions). When User1 enters data, commiterBean for Users1 inserts the data through the appCacheBean. appCacheBean raises the event
dataInsertedand only observerBean for User1 receives the event.
ObserverBean for User2 doesn't receive the event.
If I swap Users and insert data with User2, only observerBean from user2 receives data.
Do I need to specify something in the raiseEvent or the @Observer annotations as this clearly doesn't work as I expected or as you explain.
Thanks for your help, it is greatly appreciated, I am really stuck on this...
I am desperate. I have tried everything and check with the debug.seam page that the scopes were right.
I confirm, the event producer (the one that does the Events.raiseEvent) is Application Scoped
and the other 2 beans (the one updating the cache and the one
Observingthe event) are session scoped.
I even tried with forcing the Bijections using ScopeType.Application for the event Producer bean.
I don't know why it doesn't work as I expect and as Leo described (weird, it seems to work for him and what he describes is exactly what I want to do)
Is there anything else to explore ?
What have I missed ???
By the way I am running my webapp on Tomcat 6.0.20 with Seam 2.1.1GA
Leo, can you help ? You seem to be the only one willing to reply... :-(
After reading http://seamframework.org/Community/JMSMessageListenerInAWebApplication I came up with the conclusion that I had to use JMS to
broadcastmessages across multiple user sessions.
I have created 3 app scoped seam components: MessageSession, MessagePublisher and MessageReceiver.
-creates the jms connection through factory (jndi)
-setsMessageListener to MessageReceiver
-sends a message through the MessageSession
-implements MessageListener and onMessage
-The onMessage method triggers an Events.raiseEvent
All init goes very well. JMS Messages are sent when data is updated. MessageReceiver treceives the message.
Now it seems that the onMessage method is running in a different context and the @Observers of the raised Events give null pointers for all injections.
Is this because I use WAR and Tomcat6 ?
Thanks for the help.