1 Reply Latest reply on Nov 2, 2016 12:14 PM by Max Barkley

    Errai UI with GWT

    Noah Troncoso Newbie

      I'd really like to use Errai UI(3.2.4) in my GWT (2.8) application. I already have one setup with an EntryPoint implementation and an onModuleLoad. I have restGWT setup and interacting with my server (which uses Jersey).

       

      All of the documentation I find assumes that you are building a full-on Errai project, starting from scratch using the forge addon thing. I'm not. I just want to use the templating stuff and data-binding. I'm working with a barebones setup and I can't even make a label show in my app.

       

      I have this GWT entry point:

       

      public class App implements EntryPoint
      {
          @Inject
          private ApplicationContainer applicationContainer;
      
          public void onModuleLoad()
          {
              RootPanel.get("root").add(applicationContainer);
          }
      }
      

       

      And the ApplicationContainer:

       

      @Templated
      public class ApplicationContainer extends Composite
      {
          @DataField
          private Element applicationContainer = DOM.createDiv();
      
      
          @PostConstruct
          public void init()
          {
              GWT.log("Initializing");
          }
      }
      

       

      And it's accompanying template:

       

      <div id="applicationContainer" data-field="applicationContainer">
           Application Container
      </div>
      

       

      I should see "Application Container" in the browser, but I get this error in the browser console:

       

      ComplexPanel.java:96 Uncaught TypeError: Cannot read property 'removeFromParent_0_g$' of undefined
      

       

      The widget and the template are named the same and in the same package. My widget is created just like the documentation shows: Errai Getting Started Guide

       

      Can someone tell me what I'm missing here? Examples for this are very minimal, and they all assume a complete Errai project. Do I still need an @EntryPoint? Do I need @PostConstruct? Is Errai even designed to work like this?\

       

      Thanks for any help.

        • 1. Re: Errai UI with GWT
          Max Barkley Expert

          Hi Noah,

           

          You are seeing the JS equivalent of a NullPointerException because the "applicationContainer" field is null. The root cause of your problem is that your EntryPoint is being created by GWT and not by Errai's dependency injection container.

           

          Most people use the container to manage the entire lifecycle of their application, in which case you can annotate a bean with @EntryPoint and one of it's methods with @PostConstruct to have that code run when the container is ready. If you do not want to do that, then you will need to use the bean manager to lookup your templated bean dynamically. Here is an example usage of the bean manager API from a test.

           

          The next issue you will run into, is that you will need to wait for the bean manager to finish initializing before calling it. You can do this with Errai's InitVotes class by registering a one time initialization callback with this method.

           

          Hope that helps.