1 Reply Latest reply on May 15, 2017 2:37 PM by Max Barkley

    Element and Widgets as child elements

    Dmitrii Tikhomirov Newbie

      Hi all, maybe someone has some ideas on how to fix my issue. In general, from my point of view, the problem is that initWidget isn't called, so (GWTMaterialDesign)  MaterialButton and MaterialDropDown aren't initialised. In case of div.add(btn)  and div.add(mdd) all worked as expected, but i need to work with Composite as a parent element for these widgets. Thanks for any help

       

       

      ps: For solution, i'll buy you a beer at the next GWTCon

       

       

      code>

              MaterialButton btn = new MaterialButton();

              btn.setActivates("qwerty");

              btn.setText("MaterialDropDown");

              btn.setIconType(IconType.MERGE_TYPE);

       

       

              MaterialDropDown mdd = new MaterialDropDown();

              mdd.setActivator("qwerty");

       

       

              MaterialLabel l1 = new MaterialLabel();

              l1.setText("L1");

              mdd.add(l1);

       

       

              // it doesn't work

              div.getElement().appendChild(btn.getElement());

              div.getElement().appendChild(mdd.getElement());

       

       

              //it works

              // div.add(btn);

              // div.add(mdd);

       

      ps: little update, i have found out  that my example works if I am adding HomePage directly to RootPanel (it's commented) but i have difficulties when i use navigation. So what are the differences between creating HomePage instance with injection and a navigation-created HomePage ?

       

       

       

      @EntryPoint
      @Templated("#body")

      public class HelloWorldClient {

         @Inject
        @DataField
         private MaterialPanel content;

         @Inject
         Logger logger;

         @Inject
         private Navigation navigation;

       

         @PostConstruct
         private void init() {

         content.add(navigation.getContentPanel());
          RootPanel.get().add(content);

         // RootPanel.get().add(homePage);

         }

       

      @ApplicationScoped
      @Templated("#root")

      @Page(path = "home", role = DefaultPage.class)

      public class HomePage extends Composite{

       

         @Inject
        @DataField("container")

        MaterialRow div;

         @Inject
         GWTMaterialInitializationContainer gWTMaterialInitializationContainer;

         @PostConstruct
         public void init() {

       

              MaterialButton btn = new MaterialButton();

              btn.setActivates("qwerty");

              btn.setText("MaterialDropDown");

              btn.setIconType(IconType.MERGE_TYPE);

       

       

              MaterialDropDown mdd = new MaterialDropDown();

              mdd.setActivator("qwerty");

       

       

              MaterialLabel l1 = new MaterialLabel();

              l1.setText("L1");

              mdd.add(l1);

       

              getElement().appendChild(btn.getElement());

              getElement().appendChild(mdd.getElement());

         }

      }

        • 1. Re: Element and Widgets as child elements
          Max Barkley Expert

          Hi Dmitrii,

           

          I'd like to help but there are some things that are unclear to me.

           

          1. If using "add" works then why are you trying to use "getElement().appendChild"?
          2. "... but i have difficulties when i use navigation" What does that mean? What are you expecting to happen and what happens instead?

           

          And on a potentially unrelated note, if you want your HomePage to be a singleton, it's better to use @Singleton than @ApplicationScoped. Both will make your page a singleton, but @ApplicationScoped will cause the bean to be proxied which is usually undesirable for UI beans.