Google Web Toolkit

Enhanced Compilation

GWT Designer adds a compilation helper that checks compilation units during build (full or incremental) for GWT-specific problems. The compilation helper checks all types referenced in the class to make sure that each type exists directly in the current GWT module or in any of the modules that are directly or indirectly included in current one (via <inherits> tags in the gwt.xml file). If a type does not exist, GWT Designer adds an error marker like the following:

com.google.gwt.xml.client.XMLParser can not be found in source packages. Check the inheritance chain from your module;
      it may not be inheriting a required module or a module may not be adding its source path entries properly

Note that only referenced types are checked; not referenced methods.
 

Compiler checks for types emulated by GWT. Referenced types (like java.util.LinkedList) that are not emulated are flagged with an error.


 

Compiler checks for referenced types that are not properly inherited via the gwt.xml file.

For example:

  • Referencing the GWT Document or XMLParser classes will trigger an error
     
  • Adding an <inherits> tag referencing the com.google.gwt.xml.XML package to the gwt.xml file will recompile the project and remove the error


 

A QuickFix is available for adding <inherits name="module.name"/>


 

Compiler adds a warning for Composites without a default constructor.

Custom widgets and Composites must have a default constructor in order to be used within GWT Designer.


 

Code that is inappropriate for design time may be hidden with isDesignTime() checks.
  • Hide code that only works at runtime such as references to RemoteService instances
     
  • Hide code that should not be reflected in the design view (i.e., a call to setVisible(false))
     
  • Hide code that is expensive to execute at design time (e.g., database calls)

Remote Services are runtime-only components and care must be taken when trying to use them at design time in a Composite class. GWT.create(MyService.class) needs to create an instance of the class that should invoke the RemoteService implementation on the application server. During design time the application server isn't running so this doesn't work. That means that code like the following will fail, if you try to use the custom Composite within another window at design time:

public class MyComposite extends Composite {
    public MyComposite() {
        final AbsolutePanel absolutePanel = new AbsolutePanel();
        initWidget(absolutePanel);
        final Button button = new Button();
        absolutePanel.add(button, 30, 34);
        button.setText("New Button");
        MyServiceAsync service = MyService.Util.getInstance(); //this line will fail
        // do something with MyService
    }
}

At design time, you will see an exception like the following:

java.lang.NoSuchMethodException: com.mycompany.module.client.MyService.<init>()
    at java.lang.Class.getConstructor0(Class.java:2678)
    at java.lang.Class.getDeclaredConstructor(Class.java:1953)
    at com.google.gwt.core.client.GWT.create(Unknown Source)

The fix is to wrapper the RemoteService instantiation reference in an isDesignTime() check like this:

public class MyComposite extends Composite {
    public MyComposite() {
        final AbsolutePanel absolutePanel = new AbsolutePanel();
        initWidget(absolutePanel);
        final Button button = new Button();
        absolutePanel.add(button, 30, 34);
        button.setText("New Button");
        if (!isDesignTime()) { // or !Beans.isDesignTime() in GWT 2.4 or higher
            MyServiceAsync service = MyService.Util.getInstance();
            // do something with MyService
        }

    }
    // Implement the following method exactly as-is
    private static final boolean isDesignTime() {
        return Beans.isDesignTime(); // GWT 2.4 and above
        // return false // GWT 2.2 and earlier
    }

}

Make sure to also implement the isDesignTime() method exactly as shown. Return false for GWT 2.2 or earlier or Beans.isDesignTime() for GWT 2.4 and above. At design time, GWT Designer will then replace the "return false;" with "return true;" during class loading (it will compile normally and be ignored at runtime).  

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.