-
1. Re: Can't Use CDI In My View Class
shadogray Mar 8, 2013 10:35 AM (in response to chaluwa)I'm not really sure, but I assume that it doesn't make sense to set @Singleton on a GWT "view" (see http://stackoverflow.com/questions/6382473/singleton-in-gwt-project)
On the client it seems to be quite useless. So perhaps it's worth trying w/o @Singleton?
-
2. Re: Can't Use CDI In My View Class
mdhirsch30345 Mar 12, 2013 3:23 PM (in response to chaluwa)I have plenty of UI classes that are @Singletons, but all of them extend Composite since I want to use them in my display. You might try making your class extend composite or Widget. I'm not sure that you can display a non-widget class at all, anyway.
-
3. Re: Can't Use CDI In My View Class
chaluwa Mar 12, 2013 4:50 PM (in response to mdhirsch30345)Thanks Michael. So what exactly does the @Singleton annotation mean / do to a UI class? even one that extends Composite.
-
4. Re: Can't Use CDI In My View Class
mdhirsch30345 Mar 12, 2013 6:10 PM (in response to chaluwa)I use it when I have a widget that I want to display, but no matter how it is displayed I want to show the same instance of the widget. Like, perhaps, a settings panel. You don't need two different settings panels, so you create a Singleton. Any class that wants to display the settings panel would create an instance, like
@Inject
Instance<SettingsPanel> spInst;
Then later when you want to display it:
spInst.get().display()
So the panel lies hidden until requested, and whenever it is requested the same object is displayed.
-
5. Re: Can't Use CDI In My View Class
chaluwa Mar 13, 2013 4:04 AM (in response to mdhirsch30345)Thanks Michael, am grateful. I have @Inject private Caller<MyRpcService> cloud; in the view class that I want to annotate with @Singleton (or @ApplicationScoped if its the right / better way) but I am getting a null pointer exception at the point where I try to do cloud.call(...), meaning the Caller object is not been injected.
Do I need to annotate a view class (with @Singleton or @ApplicationScoped, or whatever) to correctly inject a Caller, and why is my Caller object still null. Am also confused which import to use for the @Singleton (javax.ejb or javax.inject) and @ApplicationScoped (javax.enterprise.context or javax.ejb) annotations since I see several.
Right now, since my Caller object is null, am using the MessageBuilder API. Thanks for help in advance.
-
6. Re: Can't Use CDI In My View Class
shadogray Mar 13, 2013 5:11 PM (in response to chaluwa)You are right, these annotations have become a mess..
But as a rule of thumb: do not use the javax.ejb.* annotations, its javax.enterprise.context.ApplicationScoped and javax.inject.Singleton
You can see this e.g. in https://github.com/errai/errai/blob/master/errai-ioc/src/main/java/org/jboss/errai/ioc/rebind/ioc/bootstrapper/IOCBootstrapGenerator.java
If your injection targets are null, please check how you instantiate the class. If you call the constructor youself, injection will _not_ happen.
Injection only happens, if you get the objects by calls to the CDI framework!
Such cases are e.g.: @EntryPoint, @Page if using transitions, @Inject on fields of CDI-aware objects, @Inject Instance<T> xxx,
It is easy to overlook a selfinstantiating constructor, which will produce a non-CDI-aware object.