2
votes

ConfigProperty.idPropertyMap is filled on the server side. (verified via log output)
Accessing it on the client side shows it's empty. :-( (verified via log output)

Is this some default behaviour? (I don't think so) Is the problem maybe related to the inner class ConfigProperty.IdPropertyMap, java.util.HashMap usage, serialization or some field access modifier issue?

Thanks for your help

    // the transfer object

    public class ConfigProperty implements IsSerializable, Comparable {

        ...

    static public class IdPropertyMap extends HashMap 
             implements IsSerializable 
        {
           ...
        }

    protected static IdPropertyMap idPropertyMap = new IdPropertyMap();

        ...
    }


    // the server service

    public class ManagerServiceImpl extends RemoteServiceServlet implements
        ManagerService 
    {
        ...

        public IdPropertyMap getConfigProps(String timeToken) 
            throws ConfiguratorException 
        {
            ...
        }
    }

added from below after some good answers (thanks!):

answer bottom line: static field sync is not implemented/supported currently. someone/me would have to file a feature request

just my perspective (an fallen-in-love newby to GWT :-)):

I understand pretty good (not perfect! ;-)) the possible implications of "global" variable syncing (a dependency graph or usage of annotations could be useful). But from a new (otherwise experienced Java EE/web) user it looks like this:

  • you create some myapp.shared.dto.MyClass class (dto = data transfer objects)

  • you add some static fields in it that just represent collections of those objects (and maybe some other DTOs)

  • you can also do this on the client side and all the other static methods work as well

  • only thing not working is synchronization (which is not sooo bad in the first place)

BUT: some provided annotation, let's say @Transfer static Collection<MyClass> myObjList; would be handy, since I seem to know the impact and benefits that this would bring.

In my case it's rather simple since the client is more static, but would like to have this data without explicitely implementing it if the GWT framework could do it.

2
changing protected ... idPropertyMap to public ... did not help.Andreas Covidiot
btw. I am using GWT 2.5.0, runtime code is JRE 6 compatible, internal Jetty on jre7x64bit, Eclipse Juno 64bit on 64bit jre7x64bit JVM, Win7 64bitAndreas Covidiot
You may add your comments to the original post.Artemix
@Artemix: did just this. thanksAndreas Covidiot

2 Answers

3
votes

static variables are purely class variable It has nothing to do with individual instances. serialization applies only to object.

So ,your are getting always empty a ConfigProperty.idPropertyMap

3
votes

The idea of RPC is not that you can act as though the client and the server are exactly the same JVM, but that they can share the objects that you pass over the wire. To send a static field over the wire, from the server to the client, the object stored in that field must be returned from the RPC method.

Static properties are not serialized and sent over the wire, because they do not belong to a single object, but to the class itself.

public class MyData implements Serializable {
    protected String name;//sent over the wire, each MyData has its own name
    protected String key;

    protected static String masterKey;//All objects on the server or client 
    // share this, it cannot be sent over RPC. Instead, another RPC method
    // could access it
}

Note, however, that it will only be that one instance which will be shared - if something else on the server changes that field, all clients which have asked for a copy will need to be updated