8 Replies Latest reply on Jun 3, 2015 9:05 AM by yocha

    @ApplicationScoped failures in Errai 3.1.2

    hr.stoyanov

      hello all,

      I noticed that this configuration of beans fails:

       

      ....

      @ApplicationScoped @Templated("BottomBar.html#bottomBar")

      public class BottomBar extends Composite {

      ...

      }

       

      @ApplicationScoped @Page(path = "faq") @Templated("FAQ.html#faq")

      public class FAQPage extends AbstractTextPage {

          @Inject @DataField    private BottomBar bottomBar;

      }

       

      It looks like Errai 3.1.2 can not instantiate the application-scoped beans in the right order? If I remove @ApplicationScoped from BottomBar, all works fine. Is this a known issue or limitation?

       

      Here are stack some traces:

      =====================================

      21:26:30 SEVERE [AbstractCreationalContext] error initializing bean: com.xxx.gwt.client.local.help.HelpPage

      Uncaught java.lang.RuntimeException: critical error in IOC container bootstrap: java.lang.RuntimeException: error in bean initialization

      21:26:31 SEVERE [AbstractCreationalContext] error initializing bean: com.xxx.gwt.client.local.picks.PicksPage

      Got invalid page name "PicksPage". Redirecting to default page.

      java.lang.RuntimeException: error in bean initialization

        at fillInStackTrace_0_g$

        at Throwable_3_g$

        at Exception_3_g$

        at RuntimeException_3_g$

        at fireAllInitCallbacks_0_g$

        at finish_3_g$

        at getInstance_174_g$

        at getInstance_178_g$

        at produceContent_0_g$

        at maybeShowPage_0_g$

        at navigate_0_g$

        at onValueChange_8_g$

        at dispatch_79_g$

        at dispatch_80_g$

        at dispatch_0_g$

        at dispatchEvent_2_g$

        at doFire_0_g$

        at fireEvent_2_g$

        at fireEvent_1_g$

        at fireEvent_3_g$

        at fire_10_g$

        at fireValueChangedEvent_0_g$

        at fireCurrentHistoryState_0_g$

        at fireCurrentHistoryState_1_g$

        at run_44_g$

        at run_29_g$

        at _runAllRunnables_1_g$

        at _runAllRunnables_0_g$

        at finishInit_0_g$

        at run_27_g$

        at run_30_g$

        at run_31_g$

        at fire_0_g$

        at anonymous

        at apply_43_g$

        at entry0_0_g$

        at anonymous

      Caused by: java.lang.IllegalStateException: Cannot set a new parent without first clearing the old parent

        at fillInStackTrace_0_g$

        at Throwable_2_g$

        at Exception_2_g$

        at RuntimeException_2_g$

        at IllegalStateException_2_g$

        at setParent_2_g$

        at setParentNative_0_g$

        at TemplateWidget_1_g$

        at initWidget_1_g$

        at init_186_g$

        at init_45_g$

        at fireAllInitCallbacks_0_g$

        at finish_3_g$

        at getInstance_174_g$

        at getInstance_178_g$

        at produceContent_0_g$

        at maybeShowPage_0_g$

        at navigate_0_g$

        at onValueChange_8_g$

        at dispatch_79_g$

        at dispatch_80_g$

        at dispatch_0_g$

        at dispatchEvent_2_g$

        at doFire_0_g$

        at fireEvent_2_g$

        at fireEvent_1_g$

        at fireEvent_3_g$

        at fire_10_g$

        at fireValueChangedEvent_0_g$

        at fireCurrentHistoryState_0_g$

        at fireCurrentHistoryState_1_g$

        at run_44_g$

        at run_29_g$

        at _runAllRunnables_1_g$

        at _runAllRunnables_0_g$

        at finishInit_0_g$

        at run_27_g$

        at run_30_g$

        at run_31_g$

        at fire_0_g$

        at anonymous

        at apply_43_g$

        at entry0_0_g$

        at anonymous

       

       

      Async Task Execution Failed. Future executions (if any) are cancelled.

      com.google.gwt.event.shared.UmbrellaException: Exception caught: This UIObject's element is not set; you may be missing a call to either Composite.initWidget() or UIObject.setElement()

        at fillInStackTrace_0_g$

        at Throwable_3_g$

        at Exception_3_g$

        at RuntimeException_3_g$

        at UmbrellaException_3_g$

        at UmbrellaException_5_g$

        at fireEvent_1_g$

        at fireEvent_3_g$

        at fire_10_g$

        at fireValueChangedEvent_0_g$

        at fireCurrentHistoryState_0_g$

        at fireCurrentHistoryState_1_g$

        at run_44_g$

        at run_29_g$

        at _runAllRunnables_1_g$

        at _runAllRunnables_0_g$

        at finishInit_0_g$

        at run_27_g$

        at run_30_g$

        at run_31_g$

        at fire_0_g$

        at anonymous

        at apply_43_g$

        at entry0_0_g$

        at anonymous

      Caused by: java.lang.AssertionError: This UIObject's element is not set; you may be missing a call to either Composite.initWidget() or UIObject.setElement()

        at fillInStackTrace_0_g$

        at Throwable_3_g$

        at Error_3_g$

        at AssertionError_7_g$

        at makeAssertionError_Object_0_g$

        at getElement_3_g$

        at setWidget_2_g$

        at setWidget_1_g$

        at setWidget_8_g$

        at callback_52_g$

        at callback_40_g$

        at callback_39_g$

        at getInstance_178_g$

        at fireAsync_1_g$

        at run_45_g$

        at proceed_0_g$

        at pageHiding_0_g$

        at callback_50_g$

        at callback_51_g$

        at getInstance_178_g$

        at produceContent_13_g$

        at maybeShowPage_0_g$

        at navigate_0_g$

        at navigate_2_g$

        at navigate_1_g$

        at goTo_2_g$

        at handleInvalidPageNameError_0_g$

        at onValueChange_8_g$

        at dispatch_79_g$

        at dispatch_80_g$

        at dispatch_0_g$

        at dispatchEvent_2_g$

        at doFire_0_g$

        at fireEvent_2_g$

        at fireEvent_1_g$

        at fireEvent_3_g$

        at fire_10_g$

        at fireValueChangedEvent_0_g$

        at fireCurrentHistoryState_0_g$

        at fireCurrentHistoryState_1_g$

        at run_44_g$

        at run_29_g$

        at _runAllRunnables_1_g$

        at _runAllRunnables_0_g$

        at finishInit_0_g$

        at run_27_g$

        at run_30_g$

        at run_31_g$

        at fire_0_g$

        at anonymous

        at apply_43_g$

        at entry0_0_g$

        at anonymous

        • 1. Re: @ApplicationScoped failures in Errai 3.1.2
          yocha

          I have just discovered this same (unexpected) behaviour with the version 3.2.0-SNAPSHOT.

          • 2. Re: @ApplicationScoped failures in Errai 3.1.2
            ddadlani

            Hello Hristo,

             

            We do have tests that check for this behaviour and there don't seem to be any issues. Could you give us some more detail? What exactly is the AbstractTextPage doing?

             

            Cheers,
            Divya

            • 3. Re: @ApplicationScoped failures in Errai 3.1.2
              hr.stoyanov

              Divya,

              Here is the rest of the code, the hierachy goes like this: Composite->AbstractBasePage->AbstractTextPage->FAQPAge. The singleton S4GWebApp is injected in the root, so it is available in each page. GA is for Google Analytics tracking.  Not sure why there is an issue, but it sounds like Errai DI gets confused with class hierarchies >2 levels deep. Do you test cases cover deeper hierarchies?

               

               

              public class AbstractTextPage extends AbstractBasePage {

                  @Override protected void pageShowing() {

                      theWebApp .getHeaderMenu() .showSideBar().showLogIn() .showSearch() .hideRundateItem();

                  }

              }

              ...

              abstract public class AbstractBasePage extends Composite {

                  @Inject  protected S4GWebApp theWebApp;

                  @PageShown protected  void pageShown() {

                      GATracker.trackPageview();

                  }

               

               

                  @PageShowing protected  void pageShowing() {

                  }

                 

                  @PageHiding protected void pageHiding(){

                      SUIPopUp.hideAllPopus();

                  }

              }

              • 4. Re: @ApplicationScoped failures in Errai 3.1.2
                hr.stoyanov

                Yohann, this is an issue in 3.1.2. It would be nice if Christian&Co fix it before releasing 3.2.0 :-)

                • 5. Re: @ApplicationScoped failures in Errai 3.1.2
                  yocha

                  Yes, it would be ! :-)

                  I just tried this simple code that ends up by the error message: "Uncaught java.lang.RuntimeException: critical error in IOC container bootstrap: java.lang.RuntimeException: error in bean initialization".

                  (from version 3.2.0-SNAPSHOT)

                   

                  --------------------------------------------

                  @ApplicationScoped

                  @Page(role = DefaultPage.class)

                  @Templated

                  public class Page1 extends Composite {

                   

                    @Inject

                    @DataField

                    private Child child;

                  }

                  --------------------------------------------

                  @ApplicationScoped

                  @Page

                  @Templated

                  public class Page2 extends Composite {

                   

                    @Inject

                    @DataField

                    private Child child;

                  }

                  --------------------------------------------

                  @ApplicationScoped

                  @Templated

                  public class Child extends Composite {}

                  --------------------------------------------

                   

                  The errors displayed into browser console:

                   

                  SEVERE [AbstractCreationalContext] error initializing bean: xxx.client.local.test.yocha.bug.Page2

                  error_1_g$ @ ConsoleLogHandler.java:69

                  publish_0_g$ @ ConsoleLogHandler.java:54

                  log_14_g$ @ LoggerImplRegular.java:110

                  log_17_g$ @ LoggerImplSevere.java:68

                  log_13_g$ @ LoggerImplRegular.java:98

                  log_16_g$ @ LoggerImplSevere.java:61

                  log_21_g$ @ Logger.java:103

                  log_18_g$ @ JULLogger.java:373

                  error_10_g$ @ JULLogger.java:365

                  fireAllInitCallbacks_0_g$ @ AbstractCreationalContext.java:203

                  finish_3_g$ @ SimpleCreationalContext.java:177

                  bootstrapContainer_2_g$ @ Container.java:78

                  onModuleLoad_8_g$ @ Container.java:41

                  init_2_g$ @ org_00046silverpeas_00046poc_00046SilverpeasPoc__EntryMethodHolder.java:3

                  initializeModules_0_g$ @ ModuleUtils.java:44

                  apply_40_g$ @ Impl.java:247

                  entry0_0_g$ @ Impl.java:306

                  (anonymous function) @ Impl.java:72

                  gwtOnLoad_0_g$ @ ModuleUtils.java:55

                  (anonymous function) @ Collection.java:25

                   

                   

                  Uncaught java.lang.RuntimeException: critical error in IOC container bootstrap: java.lang.RuntimeException: error in bean initialization

                  bootstrapContainer_2_g$ @ Container.java:84

                  onModuleLoad_8_g$ @ Container.java:41

                  init_2_g$ @ org_00046silverpeas_00046poc_00046SilverpeasPoc__EntryMethodHolder.java:3

                  initializeModules_0_g$ @ ModuleUtils.java:44

                  apply_40_g$ @ Impl.java:247

                  entry0_0_g$ @ Impl.java:306

                  (anonymous function) @ Impl.java:72

                  gwtOnLoad_0_g$ @ ModuleUtils.java:55

                  (anonymous function) @ Collection.java:25

                   

                   

                  Hristo, What is the identifier of the referenced bug issue ?

                  Maybe that adding this simple code to the topic could help :-)

                  • 6. Re: @ApplicationScoped failures in Errai 3.1.2
                    ddadlani

                    Hello Yohann,

                     

                    This is not a bug. An injected bean can only have one parent at a given time. Since both pages and the Child widget are all application scoped, the parent of the Child widget never gets destroyed and hence a new parent cannot be set.

                     

                    Cheers,
                    Divya

                    • 7. Re: @ApplicationScoped failures in Errai 3.1.2
                      ddadlani

                      Hristo,

                       

                       

                      What exactly are you trying to accomplish? From your code it appears that you require certain widgets to appear on every page, such as the BottomBar. Have you taken a look at the Grocery List demo? From my understanding, the GroceryListClient might be a helpful example.

                       

                      Cheers,
                      Divya

                      • 8. Re: @ApplicationScoped failures in Errai 3.1.2
                        yocha

                        Thank you for your answer that explain clearly to me that I was missing something!

                         

                        Since these last months, I worked with CDI on server-side (JEE project) and that is why I took some thinking shortcuts about @ApplicationScoped and @Singleton annotations.

                        Indeed, I was expecting from them a very similar behavior into errai framework, but it is today not possible to get it for Widget components because of the reasons you gave.

                         

                        However, do you think it could be possible, for widgets annotated with @ApplicationScoped or @Singleton, that the parent is set again at each page transition (if the next or previous page is different than the current one)?

                        If it is, it could be an awesome feature!

                         

                        Thank you for your time.