-
1. Re: Nullable conversation scoped component
swd847 Apr 7, 2010 3:48 AM (in response to phantasmo)What about this:
@ConversationScoped public class Manager { SomeObject selected; @Producer @RequestScoped public SomeObject produceSelected() { return selected; } }
-
2. Re: Nullable conversation scoped component
phantasmo Apr 7, 2010 9:46 AM (in response to phantasmo)Wait a sec, the spec says:
If a producer method sometimes returns a null value, then the producer method must have scope @Dependent.And in my case (using your example), SomeObject can be null. Won't this be a problem?
Thanks!
-
3. Re: Nullable conversation scoped component
nickarls Apr 7, 2010 9:50 AM (in response to phantasmo)I think so. The products are checked for this.
-
4. Re: Nullable conversation scoped component
phantasmo Apr 7, 2010 9:55 AM (in response to phantasmo)Just for the sake of future searches, I'll add that I am trying to achieve something like this:
@Scope(ScopeType.SESSION) public class Manager { @Out(required=false) SomeObject selected; //not really relevant public void findSelected(int id) { selected = em.find(SomeObject.class, id); } }
-
5. Re: Nullable conversation scoped component
phantasmo Apr 10, 2010 3:05 PM (in response to phantasmo)This is a fairly common scenario, could it be that there's no straightforward way of implementing it?
Maybe I'm missing something...Anyway, I'll appreciate any shared ideas...
-
6. Re: Nullable conversation scoped component
nickarls Apr 12, 2010 8:33 AM (in response to phantasmo)I generally prefer returning an object, anyway, something like
public class User { public static final User NONE = new User(); }
and check against that instead of null.
-
7. Re: Nullable conversation scoped component
phantasmo Apr 12, 2010 9:29 PM (in response to phantasmo)Well... null was defined for a reason... Things like this force you to work around the framework instead of working with it. And that's never a good sign. The more I learn the more flawed CDI looks. I genuinely hope I just didn't get it right.
Anyway, excuse my rambling Nicklas, I am grateful for your attempts to help.
-
8. Re: Nullable conversation scoped component
nickarls Apr 12, 2010 11:06 PM (in response to phantasmo)Generally, if the framework imposes a limitation on you, it's because it wants you to protect you from something else ;-) Of course, there may be a simple CDI:ish workaround to this that doesn't some to mind right now...