-
1. Re: Question about Seam Events and components scope
lvdberg Jun 26, 2009 8:26 PM (in response to teknologist)Eric,
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).
Leo
-
2. Re: Question about Seam Events and components scope
teknologist Jun 26, 2009 8:34 PM (in response to teknologist)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
broadscasts
events to all the instances of the session scoped bean ?Is this possible using Events ?
Thanks in advance,
--Eric
-
3. Re: Question about Seam Events and components scope
teknologist Jun 26, 2009 8:55 PM (in response to teknologist)Hi Leo,
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
appCacheBean
.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(dataInserted
)The other session bean that @Observes the
dataInserted
event and updates the user session UI. Lets call itobserverBean
.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
dataInserted
and 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.
Weird...
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...
Cheers,
--Eric
-
4. Re: Question about Seam Events and components scope
teknologist Jun 27, 2009 3:34 AM (in response to teknologist)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
Observing
the 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
Thanks anyway....
Leo, can you help ? You seem to be the only one willing to reply... :-(
-
5. Re: Question about Seam Events and components scope
teknologist Jun 28, 2009 12:35 PM (in response to teknologist)After reading http://seamframework.org/Community/JMSMessageListenerInAWebApplication I came up with the conclusion that I had to use JMS to
broadcast
messages across multiple user sessions.I have created 3 app scoped seam components: MessageSession, MessagePublisher and MessageReceiver.
MessageSession:
-creates the jms connection through factory (jndi)
-creates session
-creates producer/topic
-creates consumer
-setsMessageListener to MessageReceiverMessagePublisher:
-sends a message through the MessageSessionMessageReceiver:
-implements MessageListener and onMessage
-The onMessage method triggers an Events.raiseEventAll 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.