-
1. Re: Errai UI - Singleton composite in page layout using Errai Navigation
jfuerth Apr 5, 2013 2:25 PM (in response to f.sauter)Hi Flori,
Yes, either @Singleton or @ApplicationScoped on your SideBarComponent should be sufficient. The code that makes the instance looks like this:
public void produceContent(CreationalCallback callback) { bm.lookupBean(YourPageClass.class).getInstance(callback); }
The bm variable is the Errai client-side AsyncBeanManager, inherited from NavigationGraph. You can double-check this code in your own project in .errai/GeneratedNavigationGraph.java.
Is it possible something old is stuck in dev mode? Have you tried stopping dev mode and cleaning your project?
-Jonathan
-
2. Re: Errai UI - Singleton composite in page layout using Errai Navigation
jfuerth Apr 5, 2013 2:32 PM (in response to jfuerth)1 of 1 people found this helpfulOh wait!
What I said in my previous post is only true for @Page classes. I believe that when a template is being composited, the @Injected templated beans are always newly instantiated regardless of their scope.
Probably your best bet would be to keep that state in a separate @ApplicationScoped bean and @Inject that bean into SideBarComponent:
@ApplicationScoped public class SideBarTransactions { private List<Transaction> transactions; @AfterInitialization private void init() { // load transactions } public List<Transaction> get() { return transactions; } }
Hope that helps!
-Jonathan
-
3. Re: Errai UI - Singleton composite in page layout using Errai Navigation
f.sauter Apr 6, 2013 10:37 AM (in response to jfuerth)Thanks Jonathan, I'll use the seperate bean for now but it would be really nice to have the possibility to declare a singleton composite for page layouts like in GWTP a singleton PresenterWidget.
BTW: Here is the stacktrace which occurs if I try to annotate my SideBarComponent with @Singleton or @ApplicationScoped (Errai 2.3.0.CR1): http://pastebin.com/rFptVe0e