3 Replies Latest reply on Dec 8, 2014 1:53 PM by csa

    Is @StyleBinding supported on @Templated composite components?

    lukasherman

      A complex UI based on template contains custom components, also build on templates. A modified StyleBoundTemplate.java test case looks like:

       

      @Templated

      public class StyleBoundTemplate extends Composite {

        @Inject @AutoBound DataBinder<TestModel> dataBinder;

        @Inject @Bound @AdminBinding @DataField private Label testA;

        @Inject @Bound @TestBinding @DataField private Label testB;

        @Inject @Bound @ComponentBinding @DataField private CustomComponent testC;

      ...

       

       

      An attempt to implement @StyleBinding on CustomComponent results in error:

       

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

        at com.google.gwt.user.client.ui.UIObject.getElement(UIObject.java:558)

        at org.jboss.errai.ioc.client.BootstrapperImpl$9.getInstance(BootstrapperImpl.java:218)

        at org.jboss.errai.ioc.client.BootstrapperImpl$9.getInstance(BootstrapperImpl.java:1)

        at org.jboss.errai.ioc.client.container.IOCDependentBean.getInstance(IOCDependentBean.java:96)

        at org.jboss.errai.ioc.client.container.IOCDependentBean.getInstance(IOCDependentBean.java:87)

        at org.jboss.errai.ui.test.stylebinding.client.StyleBindingTest.testStyleBinding(StyleBindingTest.java:38)

       

      It looks like templated component method initWidget() in generated BootstrapperImpl.java is called in context.initializationCallback(), but the method addElementBinding() is called before the component is fully initialized.

       

      StyleBindingsRegistry.get().addElementBinding(inj568_StyleBoundTemplate, _$1399813453ComponentBinding_0, _$188674782__600660785_testC(inj568_StyleBoundTemplate).getElement());

       

      The resulting exception is:

       

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

        at com.google.gwt.user.client.ui.UIObject.getElement(UIObject.java:558)

        at org.jboss.errai.ioc.client.BootstrapperImpl$9.getInstance(BootstrapperImpl.java:218)

        at org.jboss.errai.ioc.client.BootstrapperImpl$9.getInstance(BootstrapperImpl.java:1)

        at org.jboss.errai.ioc.client.container.IOCDependentBean.getInstance(IOCDependentBean.java:96)

        at org.jboss.errai.ioc.client.container.IOCDependentBean.getInstance(IOCDependentBean.java:87)

       

      How to ensure the custom component is initialized before addElementBinding() is called? Is it safe to move addElementBinding() into initializationCallback() ? Is the initializationCallback() calling order guaranteed, so that inner components inside the template are initialized before main component?