5 Replies Latest reply on Apr 16, 2016 6:14 PM by Hristo Stoyanov

    [4.0.0-SNAPSHOT] Is this Errai 4 or GWT 2.8 compiler issue?

    Hristo Stoyanov Master

      I am using the latest 4/13 snapshots for both Errai 4 and GWT 2.8, and I obeserve a bizare issue, which could be Errai generated proxy problem, or GWT compiler issue - not sure. Here are a couple of classes, hopefully simple and  self-explanatory. I captured the bizarre behavior in 2 Chrome debug session screenshots - the element argument becomes "undefined" when calling the static method, causing JS error!?

       

      import org.jboss.errai.common.client.dom.HTMLElement;

      abstract public class ElementUtils {

          private ElementUtils() {}

         static public void setVisible(HTMLElement element, boolean visible) {

              element.getStyle().setProperty("visibility", visible ? "visible" : "hidden");

          }

      }

       

       

       

      import org.jboss.errai.common.client.dom.Anchor;

      @Templated("Skeleton.html#headerMenu") @ApplicationScoped

      public class HeaderMenu extends BaseMenu implements IsElement {

          ...

          @Inject @DataField @Named("a")

          private Anchor sandwichItem;

       

       

          @EventHandler(value = "searchItem")

          private void onClickSearch(ClickEvent e) {

              toggleSearch(true);

          }

         

          private void toggleSearch(boolean showSearch){

              ElementUtils.setVisible(sandwichItem, !showSearch);      

          }

      }

        • 1. Re: [4.0.0-SNAPSHOT] Is this Errai 4 or GWT 2.8 compiler issue?
          Hristo Stoyanov Master

          .. not seen in the attached screenshots, but the second boolean argument is coming through fine. Also, moving the setVisible method into the HeaderMenu class, or inlining the method  does not help. Here is the actual JS error:

          Exception: com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'style' of undefined

           

          I attached a new screenshot that shows that this might be an issue with the Errai generated proxy?Capture3.PNG

          • 2. Re: [4.0.0-SNAPSHOT] Is this Errai 4 or GWT 2.8 compiler issue?
            Max Barkley Expert

            Hi Hristo,

             

            From the last PNG it looks like the function call you are in has been invoked on the proxy and not the actual type, so the field that is passed in as the first parameter is undefined. I might be able to tell you more if I see the call stack. In particular, we want to find the first stack frame where a method on HeaderMenu is invoked. Is there a package private method you are using on this type? The container cannot proxy package private methods, so if you call a package private method from the outside of an @ApplicationScoped beans it will not be redirected to the actual instance and could cause a problem like this.

            • 3. Re: [4.0.0-SNAPSHOT] Is this Errai 4 or GWT 2.8 compiler issue?
              Hristo Stoyanov Master

              Max,

              Indeed, the call chain starts from a package private method, and it did occur to me after reading your Errai4 migration notes in the docs!

              Without knowing the reason for the resriction, I think there should be a better way to handle this - a runtime warning at a minimum. Mystery JS errors is not OK.

               

              I also noticed that for Element injection you have to provide @Named("tag"). I saw that in the console log at runtime. Can this be made a compile time error? Also, I think I had a case when the annotation was missing and nobody complained, but I have to hunt down this case to show you ...

               

              Thanks for your support, Errai 4 is shaping to be awesome!

              • 4. Re: [4.0.0-SNAPSHOT] Is this Errai 4 or GWT 2.8 compiler issue?
                Max Barkley Expert
                Without knowing the reason for the resriction, I think there should be a better way to handle this - a runtime warning at a minimum. Mystery JS errors is not OK.

                There are warnings about this in the build logs, but we can't fail the build for this because it would make it impossible to have @ApplicationScoped classes extending Widget.

                I also noticed that for Element injection you have to provide @Named("tag"). I saw that in the console log at runtime.

                I'm not sure what logging you're referring to. You don't always have to use the @Named to inject an element. That's only necessary if there is ambiguity (i.e. for elements that have multiple tags). As per the CDI spec @Named beans are also @Default, so if there is only one bean satisfying an element (like the @Named("a") Anchor) you do not need the @Named on the injection site. In cases where the @Named is necessary you should see rebind errors for ambiguous dependencies.

                • 5. Re: [4.0.0-SNAPSHOT] Is this Errai 4 or GWT 2.8 compiler issue?
                  Hristo Stoyanov Master

                  Max, OK I see about @Named, but here is what I observed:

                  1. I did not see any warning about the package private issue in any log (Chrome, superdev, compiler). Just JS error as seen in the screenshot.

                  2. I saw a warning for needed @Named annotation in the Chrome console.