-
1. Re: Qualifier with one or more values
awestwel Mar 29, 2010 7:29 PM (in response to awestwel)Just to clarify I have a qualifier hold a single string value. But I want the event to fire if the value matches one of the values. So in the example if the qualifier values is
First
orSecond
Thanks
-
2. Re: Qualifier with one or more values
nickarls Mar 30, 2010 8:54 AM (in response to awestwel)I'm not following, could you please write some code and explain what is happening and what you expected to happen. If you want to control what is fired, wrap the firing in a method that checks the incoming data if to fire?
-
3. Re: Qualifier with one or more values
awestwel Mar 30, 2010 2:23 PM (in response to awestwel)Hey Nicklas
Sorry for the confusion regarding my question :) So if I have the following qualifier
@Retention(RUNTIME) @Target({METHOD, TYPE}) @Documented @Qualifier public @interface TestQualifier { String value(); }
Then in my manager class I want to observer an event when value has one or more values that match. Is this possible
@Singleton public class TestManager { private void transactionEvent(@Observes @TestQualifier({"First", Second"}) { } }
Is this possible with the CDI event bus?
-
4. Re: Qualifier with one or more values
nickarls Mar 30, 2010 5:57 PM (in response to awestwel)For qualifiers with binding members the equals() is called for the value. If you want more sophisticated stuff, you can fire or observe conditionally by examining the value and determine what to do yourself.
-
5. Re: Qualifier with one or more values
awestwel Mar 30, 2010 7:33 PM (in response to awestwel)How would I observe conditionally?
-
6. Re: Qualifier with one or more values
nickarls Mar 30, 2010 8:10 PM (in response to awestwel)Normal observe but you stick an if around the stuff you are about to do and check for a more specific condition. Or just exit early if the conditions are not met.
-
7. Re: Qualifier with one or more values
awestwel Mar 30, 2010 10:27 PM (in response to awestwel)I did not know you could add code conditions around an argument? Code you provide a sample on how this would look based on the code below
private void transactionEvent(@Observes @TestQualifier({"First", Second"}) { }
-
8. Re: Qualifier with one or more values
nickarls Mar 30, 2010 10:46 PM (in response to awestwel)not around the argument. see the difference:
private void doStuff(String weekday) { allWorkAndNoPlay(); }
private void doStuff(String weekday) { if ("monday".equals(weekday)) { allWorkAndNoPlay(); } }
An observer method is just a method, a parameter is just a parameter