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?
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.
Thanks Michael. So what exactly does the @Singleton annotation mean / do to a UI class? even one that extends Composite.
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
Then later when you want to display it:
So the panel lies hidden until requested, and whenever it is requested the same object is displayed.
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.
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
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.