-
1. Re: Fire a event inside a determined scope
luksa Apr 18, 2012 6:29 PM (in response to ronaldocwb)That is exactly how events work - when you fire an event in a session, only the observers in the same session will be notified (observers in other sessions will not be notified).
-
2. Re: Fire a event inside a determined scope
ronaldocwb Apr 19, 2012 9:54 AM (in response to luksa)Editing my awnser:
What realy happens is:
When I fire a event in a @ConversationScoped component, other components @ConversationScoped that are in other conversations don't cath this event. Until now great!
But i have some @ApplicationScoped and @ViewScoped that also catch it.
Can I isolate there components from my conversation or do something to my event not be captured in a scope diferent then @ConversationScoped?
-
3. Re: Fire a event inside a determined scope
kwintesencja Apr 19, 2012 12:48 PM (in response to ronaldocwb)1 of 1 people found this helpfulAs a workaround you could get the bean reference and test the beanScope in changeNotifier method,
something like:
public void changeNotifier(@Observes DetailChangeEvent event){ Bean bean = beanManager.getBeans("managedBeanName").iterator().next(); if(bean.getScope().equals(ConversationScoped.class)){//dont know if its the right way to test the bean scope log.info("Detail changed!"); } }
I didnt test but maybe it helps.
-
4. Re: Fire a event inside a determined scope
ronaldocwb Apr 19, 2012 1:18 PM (in response to kwintesencja)Rafael,
I've done some workaround and it´s working for me. But I would like to know if there is something I can do using CDI/Seam/Solder to avoid this workaround.
Thanks anyway!!!
-
5. Re: Fire a event inside a determined scope
luksa Apr 19, 2012 3:28 PM (in response to ronaldocwb)OK, I was worried when you said all other conversations also receive the event.
Anyway, CDI doesn't have anything that would deliver events only to observers in the same scope type. But you can use different event types or different event qualifiers to achieve what you want.
Something like:
@Inject @ConversationOnly Event<Foo> fooEvent;
and
void handleEvent(@Observes @ConversationOnly Foo) {
...
}
where @ConversationOnly is:
@Qualifier
@Target(PARAMETER)
@Retention(RUNTIME)
public @interface ConversationOnly {
String value();
}
Note: @ConversationOnly has nothing to do with conversations or scopes. It's just a qualifier for filtering events. If you had a handleEvent(@Observes @ConversationOnly Foo) inside a @SessionScoped bean, it would be notified also, of course.
-
6. Re: Fire a event inside a determined scope
ronaldocwb Apr 19, 2012 3:33 PM (in response to luksa)Marko,
My workaround is something like this! Using qualifiers.
Thanks!