0

I am very new to GWT. I am using ext-gwt widgets.

I found many places in my office code containing like,

class A extends BaseModel{

 private UserAccountDetailsDto userAccountDetailsDto = null;

 //SETTER & GETTER IN BASEMODEL WAY
}

Also, the DTO reference is unused.

public class UserAccountDetailsDto implements Serializable{

    private Long userId=null;
    private String userName=null;
    private String userAccount=null;
    private String userPermissions=null;

        //NORMAL SETTER & GETTER
}

Now, I am able to get the result from GWT Server side Code and things Work fine, but when I comment the DTO reference inside the class A, I am not getting any Result.

Please explain me the need of that.

Thanks

Jayesh
  • 6,047
  • 13
  • 49
  • 81

2 Answers2

2

Well the problem is in implementation of GXT BaseModel and GWT-RPC serialization. BaseModel is based around special GXT map, RpcMap. This map has defined special serialization rules, which let's avoid RPC type explosion, but as side effect, only some simple types stored in map will be serialized. E.g. you can put any type inside the map, but if you serialize/deserialize it, only values of type Integer, String ,Double,Byte, Float and Short (and arrays of this types) will be present. So the meaning behind putting reference to the DTO inside BaseModel, is to tell GWT-RPC that this type is also have to be serialized.

Detailed explanation

Basically GWT-RPC works like this:

When you define an interface for service, GWT-RPC analyzes all the classes used in parameters/ return type, to create serializers/deserializers. If you return something like Map<Object,Object> from your service, GWT-RPC will have to create a serializer for each class which implements Map and Serializable interfaces, but also it will generate serializers for each class which implements Serializable. In the end it is quite a bad situation, because the size of your compiled js file will be much biggger. This situation is called GWT-RPC type explosion.

So, in the BaseModel, all values are stored in RpcMap. And RpcMap has custom written serializer (RpcMap_CustomFieldSerializer you can see it's code if you interested how to create such things), so it doesn't cause the problem described above. But since it has custom serializer GWT dosn't know which custom class have been put inside RpcMap, and it doesn't generate serializers for them. So when you put some field into your BaseModel class, gwt knows that it might need to be able to serialize this class, so it will generate all the required stuff for this class.

jusio
  • 9,850
  • 1
  • 42
  • 57
  • 1
    It may also be worth pointing out that this is all GXT 2 - the latest version, GXT 3, does not require BaseModel, and can use normal Java beans. – Colin Alworth Aug 17 '12 at 15:50
  • Yep, don't waste time deliberating about GXT2 because GXT3 is the way to go. – Eduardo Guardiola Aug 20 '12 at 11:55
  • Well, explanation is still useful to people who are stuck with GXT 2. It is not like that all existing GXT 2 projects will magically upgrade themselves to newer version=) – jusio Aug 20 '12 at 12:55
2

Porting GXT2 Application code using BaseModel to GXT3 Model is uphill task. It would be more or less completely rewrite on model side with ModelProviders from GXT3 providing some flexibility. Any code that relies on Model's events, store, record etc are in for a rewrite.

appbootup
  • 9,537
  • 3
  • 33
  • 65