Posts Tagged 'GWT'

Google GIN – A basic tutorial

17 July 2010 at 17:45 - Comments

How to work around when java.lang.Boolean is in the black list of LegacySerialiaytionPolicy

It took me a while to figure out that java.lang.Boolean is in the blacklist of the LegacySerializationPolicy class. Therefore when my RPC service tries to transfer java.lang.Boolean object, it throws Exception

"Type '*java.lang.Boolean*' was not included in the set of types which can be serialized 
by this SerializationPolicy or its Class object could not be loaded.
For security purposes, this type will not be serialized."

 

Look at the class com.google.gwt.user.server.rpc.impl.LegacySerialiaytionPolicy

  /**
   * Many JRE types would appear to be {@link Serializable} on the server.
   * However, clients would not see these types as being {@link Serializable}
   * due to mismatches between the GWT JRE emulation and the real JRE. As a
   * workaround, this blacklist specifies a list of problematic types which
   * should be seen as not implementing {@link Serializable} for the purpose
   * matching the client's expectations. Note that a type on this list may still
   * be serializable via a custom serializer.
   */
  private static final Class<?>[] JRE_BLACKLIST = {
      java.lang.ArrayStoreException.class, java.lang.AssertionError.class,
      java.lang.Boolean.class, java.lang.Byte.class, java.lang.Character.class,
      java.lang.Class.class, java.lang.ClassCastException.class,
      java.lang.Double.class, java.lang.Error.class, java.lang.Float.class,
      java.lang.IllegalArgumentException.class,
      java.lang.IllegalStateException.class,
      java.lang.IndexOutOfBoundsException.class, java.lang.Integer.class,
      java.lang.Long.class, java.lang.NegativeArraySizeException.class,
      java.lang.NullPointerException.class, java.lang.Number.class,
      java.lang.NumberFormatException.class, java.lang.Short.class,
      java.lang.StackTraceElement.class, java.lang.String.class,
      java.lang.StringBuffer.class,
      java.lang.StringIndexOutOfBoundsException.class,
      java.lang.UnsupportedOperationException.class, java.util.ArrayList.class,
      java.util.ConcurrentModificationException.class, java.util.Date.class,
      java.util.EmptyStackException.class, java.util.EventObject.class,
      java.util.HashMap.class, java.util.HashSet.class,
      java.util.MissingResourceException.class,
      java.util.NoSuchElementException.class, java.util.Stack.class,
      java.util.TooManyListenersException.class, java.util.Vector.class};

 

How to work around ?

Use a custom serializable class instead of java.lang.Boolean

import com.google.gwt.user.client.rpc.IsSerializable;

public class SerializedBoolean implements IsSerializable {

    private boolean value;

    public static final SerializedBoolean TRUE = new SerializedBoolean(true);
    public static final SerializedBoolean FALSE = new SerializedBoolean(false);

    public SerializedBoolean(){
        value = false;
    }

    public SerializedBoolean(boolean value){
        this.value = value;
    }

    public boolean isValue() {
        return value;
    }

    public void setValue(boolean value) {
        this.value = value;
    }

}
7 July 2010 at 05:55 - Comments

Some common errors when developing GWT apps

1. Use GWT.create(MyServiceAsync.class) instead of GWT.create(MyService.class)

For example:

import com.google.gwt.core.client.GWT;

public class ServiceFactory {

	private static MyServiceAsync myService = null;

	public static SecurityServiceAsync getMyService() {
		if (myService == null)
			myService = GWT.create(MyServiceAsync.class);

		return myService;
	}

}

You will get the following exception when invoking the MyService

 

Deferred binding result type ‘com.mycompany.myapp.client.MyService’ should not be abstract

Uncaught exception escaped

java.lang.RuntimeException: Deferred binding failed for 'com.mycompany.myapp.client.MyServiceAsync' (did you forget to inherit a required module?)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:43)
    at com.google.gwt.core.client.GWT.create(GWT.java:98)
    at com.mycompany.myapp.client.ServiceFactory.getMyService

 

2. CSS files are not found after deploying on appspot.com

On appspot.com, filename is case-sensitive. But in Windows, filename is case-insensitive.

21 February 2010 at 19:41 - Comments

How to debug a GWT Application with gwt-maven-plugin in Eclipse

If you are not using Eclipse and gwt-maven-plugin, please skip this post.

The following shows you how to configure Eclipse to remote debug a GWT application.

 

1. First step: Execute gwt:debug at the the command-line in the project directory

When you run gwt:debug, gwt-maven-plugin enables the remote debug mode at port 8000 (normally)

Here is what you see

image

The application stops here and listens for response from a debugger at port 8000.

 

2. Second step: configure Eclipse Debugger

In Eclipse you go to menu Run\Debug Configurations … and create a new launch configuration “Remote Java Application

Enter the host/port value as follows.

image

Now when you click Debug, the application starts running and you can see the logs continuing in the console

 

That’s it !

15 November 2009 at 09:26 - Comments