Search This Blog

Showing posts with label gwt. Show all posts
Showing posts with label gwt. Show all posts

GWT Classic DevMode

  • Has to be on Linux or Windows. Because Firefox 24 no longer available on Mac OS
  • Install GWT Eclipse Plugin
  • Make sure Eclipse is configured use JDK 8 (Java->Installed JRE)
  • Install Firefox 24.8.1 ESR
  • Install GWT Firefox Plugin (Download first, then File->Open and install it.)

GWT override css from theme


  • Create css file in com/myapp/client/resource/myapp.css:
    • body, table td, select {
        font-family: Helvetica, Arial Unicode MS, Arial, sans-serif;
        font-size: small;
      }
      
      .my-css-class {
      
      }
      
  • Create client bundle file: com.myapp.client.Resources.java:
    • package com.myapp.client;
      
      import com.google.gwt.core.client.GWT;
      import com.google.gwt.resources.client.ClientBundle;
      import com.google.gwt.resources.client.CssResource;
      public interface Resources extends ClientBundle {
        
        public static final Resources INSTANCE = GWT.create(Resources.class);
      
        public interface Style extends CssResource {
          @ClassName("my-css-class")
          myCssClass();
        }
      
        @ClientBundle.Source("resource/myapp.css") // relative path to the css file.
        @CssResource.NotStrict // No compile error if no css class in the css file.
        Style css();
      }
      
  • In the entry point class: com.myapp.client.MyAPP.java
    • package com.myapp.client;
      
      public class MyApp implements EntryPoint {
      
        public void onModuleLoadSafe() {
      
          // Inject the css
          Resources.INSTANCE.css().ensureInjected();
      
          // ... ... ...
      
        }
      
      }
      

Configure gwt-maven-plugin to start classic DevMode instead of SuperDevMode in GWT 2.7.0

In the pom.xml, pluginManagement -> plugins:
<pluginManagement>
    
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <goals>
               <goal>run</goal>
            </goals>
            <configuration>
                <extraJvmArgs>-Xmx1024m</extraJvmArgs>
                <superDevMode>false</superDevMode>
                <noServer>true</noServer>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>
Note:noServer is set true which will not start the embedded jetty web server.
For more details about the configuration options for gwt:run goal, run the following command:
mvn help:describe -Dplugin=org.codehaus.mojo:gwt-maven-plugin -Dgoal=run -Ddetail

GWT: extract protocol and host from url

AnchorElement anchor = Document.get().createAnchorElement();
anchor.setHref("http://youdomain.org/path/");
String protocol = anchor.getPropertyString("protocol");
String host = anchor.getPropertyString("host");
String path = anchor.getPropertyString("pathname");
anchor.removeFromParent();

GWT 2.5.0: gwtc failed: java.lang.RuntimeException: Unexpected IOException on in-memory stream

Got following error when compiling a GWT project using GWT 2.5.0:
[INFO]    [ERROR] Unexpected internal compiler error
[INFO] java.lang.RuntimeException: Unexpected IOException on in-memory stream
[INFO]  at com.google.gwt.dev.javac.CompilationUnit.getTypes(CompilationUnit.java:360)
Work around is remove gwt-unitCache folder.

GWT: open a url in a new browser window

com.google.gwt.user.client.Window has static method open(String url, String name, String features) can open a url in a new window:


To open a relative URL, GWT has a static method: getHostPageBaseURL() can be used, see the example below:

Google web toolkit plugin for Eclipse: Errors running builder 'Google WebApp Project Validator'

Getting this error: Errors running builder 'Google WebApp Project Validator' on project 'myproject'. when trying to build a project using ant from Eclipse. (I have a GWT project in my Eclipse workspace but the project I was trying to build has nothing to do with GWT.)

It is a bug from Google plugin for Eclipse. The work around is:
  1. In Eclipse, open "Preferences...", Select "Google", then "Web Toolkit"
  2. Select a valid GWT sdk then click "OK" button. It will rebuild your workspace and fix the error.
The bug exists in GWT 2.4.0 and 2.5.0.

How to build Google Web Toolkit DevMode plugin for Firefox 17.0 on Mac OS X

  1. Install XCode if you do not have it. (XCode 3.2.6 is recommended for building this plugin, because the source code is configured to used Mac OS 10.5 sdk, which is included in XCode 3.2.6, but it is dropped by later version XCodes. However, the later version e.g. xcode 4.3, can also be used with a few modifications on the configuration.)
  2. Check out the source code:
        svn checkout http://google-web-toolkit.googlecode.com/svn/trunk/plugins gwt/plugins
        svn checkout http://google-web-toolkit.googlecode.com/svn/plugin-sdks/gecko-sdks/gecko-17.0.0 plugin-sdks/gecko-sdks/gecko-17.0.0
      
  3. If you have xcode 3.2.6 installed, you can try to build it:
    cd gwt/plugins/xpcom && make BROWSER=ff170
  4. If you have later xcode version, e.g. xcode 4.3, installed, the command above will fail with errors finding cstdio.h. To make it work, you need to
    1. modify plugins/config.mk,
      vi ../config.mk
      change
      BASECFLAGS= $(DEBUGCFLAGS) -O2 -fPIC $(INC) -D__mac -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk -std=c++11
      to
      BASECFLAGS= $(DEBUGCFLAGS) -O2 -fPIC $(INC) -D__mac -mmacosx-version-min=10.7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -std=c++11
    2. modify gwt/plugins/xpcom/Makefile,
      vi Makefile
      change
      DLLFLAGS += -bundle $(ALLARCHCFLAGS) -mmacosx-version-min=10.5  -isysroot /Developer/SDKs/MacOSX10.5.sdk
      to
      DLLFLAGS += -bundle $(ALLARCHCFLAGS) -mmacosx-version-min=10.7  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
  5. run
    make BROWSER=ff170
    (in gwt/plugins/xpcom directory.) to build.
  6. the result plugin file will be gwt/plugins/xpcom/prebuilt/wt-dev-plugin.xpi

GWT Example: set cookies

package test;

import com.google.gwt.user.client.Cookies;

public class CookieTest {

    public static final int COOKIE_EXPIRE_DAYS = 30;
    public static final long MILLISECS_PER_DAY = 1000L * 60L * 60L * 24L;

    public static void setMyCookie(String name, String value, int days) {

    if (value == null) {
        Cookies.removeCookie(name);
        return;
    }
        String v = Cookies.getCookie(name);
        if (value.equals(v)) {
            // Now
            Date d = new Date();
            // Now + days
            d.setTime(d.getTime() + MILLISECS_PER_DAY * days);
            Cookies.setCookie(name, value, d);
        }

    }

    public static void setMyCookie(String name, String value) {
            
            setCookie(name, value, COOKIE_EXPIRE_DAYS);
    }
}

Javascript: regular expression to validate URL

function isValidURL(url) {
  var pattern = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  return pattern.test(url);
}

GWT JSNI method:

public native boolean isValidUrl(String url) /*-{
    var pattern = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
    return pattern.test(url);
}-*/;