-
1. Re: CDI Event variance
ahhughes Feb 9, 2012 8:59 AM (in response to jmfaerman)I think this is a fair question, do events need to be EXACT/EQUALS or subclass? The more I look at CDI the more 'grey areas' there are. Not that these are bad things, but no dobut they will add to the next revision. I would like to know what the spec says (or more to the point, if it even covers this). Sorry I can't answer your question.
-
2. Re: CDI Event variance
jmfaerman Feb 9, 2012 10:12 AM (in response to ahhughes)I think a lot of people will, like me, design a "AbstractEvent" with the firing date, user, etc...
I have created a sample code of the issue:
https://github.com/jfaerman/jfaerman/blob/master/test-cdi/src/main/java/jfaerman/App.java
And a copy of this question on stackoverflow (please vote):
http://stackoverflow.com/questions/9042444/how-to-use-inheritance-and-lists-of-cdi-events
So far, no solution...
-
3. Re: CDI Event variance
jharting Feb 13, 2012 8:19 AM (in response to jmfaerman)Looks like a Weld-SE related bug. Try firing the events using BeanManager directly.
-
4. Re: CDI Event variance
jmfaerman Feb 13, 2012 8:29 AM (in response to jharting)It is not... i have found this using EE on AS7 and created the test using SE just so other could reproduce easily, but the behavior is the same.
-
5. Re: CDI Event variance
jharting Feb 13, 2012 8:30 AM (in response to jmfaerman)OK, can you try it with BeanManager?
-
6. Re: CDI Event variance
jmfaerman Feb 13, 2012 10:33 AM (in response to jharting)Using the BeanManager seems to work perfectly.
Tested using this servlet:
https://github.com/jfaerman/cdi-tests/blob/master/src/main/java/jfaerman/TestEventsServlet.java
Thanks a *lot* Jozef!
-
7. Re: CDI Event variance
ceefour Aug 15, 2012 3:38 PM (in response to jmfaerman)Is BeanManager really the recommended/official way to do this?
What happened to "@Inject Event eventBus;" as how CDI makes lives easier ?
I also created a simple project to demonstrate this problem:
https://github.com/ceefour/cdifire
I think it is a bug, I really hope this gets resolved in CDI 1.1 (if not too late...)
-
-
9. Re: CDI Event variance
jmfaerman Aug 15, 2012 3:56 PM (in response to ceefour)I agree with you Hendy, please post back if you see any progress...
-
10. Re: CDI Event variance
luksa Sep 3, 2012 9:52 AM (in response to ceefour)Hendy, at least for now, the BeanManager.fireEvent is the way to go. Firing events through @Inject Event<T> is for when you want to explicitly define the event type (through T of Event<T>) to make sure the event is delivered to the observers you want.
Also, the CDI spec cannot be changed to allow injecting the Event bean without declaring the type argument (@Inject Event eventBus). If this were added to the spec, the spec would be in direct violation of the Java Language Spec, 4.8:
The use of raw types is allowed only as a concession to compatibility of legacy code. The use of raw types in code written after the introduction of genericity into the Java programming language is strongly discouraged. It is possible that future versions of the Java programming language will disallow the use of raw types.
-
11. Re: CDI Event variance
friso_caci Dec 19, 2013 10:34 AM (in response to jharting)I really like the BeanManager solution. I'm just wondering what it's doing for (or rather against?) my performance?
Am I better of firing AbstractEvent and have the handling class listen to that and delegate the call using instanceof (or something like that), or will I be fine using the BeanManager?
Groeten,
Friso