Can @ApplicationScoped annotations be used with @Templated bean?

111 Views Asked by At

I've notice that @ApplicationScoped annotations is been used only with models/services class in errai documentation.

I wonder is possible to use it with user iterface fragments, like @Templated files? For example I have one widget that is offen repeated on many @Page's. Can I use it's same instance with @Inject annotation?

If this is possible, why I am getting an error:

Uncaught Error: java.lang.IllegalStateException: This widget's parent does not implement HasWidgets
    at FBf_g$.tC_g$ [as createError_0_g$] (Throwable.java:121)
    at FBf_g$.DC_g$ [as initializeBackingError_0_g$] (Throwable.java:113)
    at FBf_g$.mC_g$ (Throwable.java:67)
    at FBf_g$.SC_g$ (Exception.java:29)
    at FBf_g$.$C_g$ (RuntimeException.java:29)
    at FBf_g$ (IllegalStateException.java:28)
    at xkj_g$.LBe_g$ [as removeFromParent_0_g$] (Widget.java:204)
    at xkj_g$ (TemplateWidget.java:43)
    at Eij_g$ (TemplateUtil.java:251)
    at mki_g$.yki_g$ [as createInstance_64_g$] (Type_factory__p_k_e_c_l_App__quals__j_e_i_Any_j_e_i_Default.java:652)
    at mki_g$.xki_g$ [as createInstance_2_g$] (Type_factory__p_k_e_c_l_App__quals__j_e_i_Any_j_e_i_Default.java:622)
    at rvi_g$.Wui_g$ [as createNewUnproxiedInstance_0_g$] (AbstractContext.java:85)
    at rvi_g$.Yui_g$ [as getActiveNonProxiedInstance_0_g$] (AbstractContext.java:78)
    at wyi_g$.Dyi_g$ [as trySettingInstance_0_g$] (ProxyHelperImpl.java:53)
    at wyi_g$.zyi_g$ [as getInstance_3_g$] (ProxyHelperImpl.java:42)
    at Uki_g$.gmi_g$ [as unwrap_1_g$] (Type_factory__p_k_e_c_l_App__quals__j_e_i_Any_j_e_i_Default.java:75)
    at Nvi_g$.Xvi_g$ [as getEagerInstance_0_g$] (ContextManagerImpl.java:72)
    at Nyi_g$.Wyi_g$ [as init_13_g$] (SyncBeanManagerImpl.java:103)
    at Nyi_g$.fzi_g$ [as setContextManager_0_g$] (SyncBeanManagerImpl.java:90)
    at d7h_g$.e7h_g$ [as bootstrapContainer_1_g$] (Container.java:80)
    at d7h_g$.g7h_g$ [as onModuleLoad_0_g$] (Container.java:40)
    at Array.Y9d_g$ (pl_00046korbeldaniel_00046erpe_00046App__EntryMethodHolder.java:3)
    at initializeModules_0_g$ (ModuleUtils.java:44)
    at Fcc_g$ (Impl.java:239)
    at Icc_g$ (Impl.java:298)
    at Impl.java:77
    at q9d_g$ (ModuleUtils.java:55)
    at MenuEntryWidget.java:43

every time I am adding: @ApplicationScoped annotation to @Templated class of widget?

1

There are 1 best solutions below

0
quarks On

In my experience, you cannot use @ApplicationScoped into a @Templated widget expect for the @EntryPoint which can also be @Templated

Hee's an example:

@ApplicationScoped
@Templated
@EntryPoint
public class App extends Composite {
}