
.. and a piece of code that assembles the panel:
PropertyGridPanel grid = new PropertyGridPanel();How does it know which editor should be attached to the value column? Simple the type is known at the compile time! One of the benefits of GWT is claimed to be its performance. It is fast, but this power comes at a price - you cannot leave the type undefined, i.e. you cannot use java.lang.Object for the type of your class members.
GridView view = new GridView();
grid.setView(view);
Map map = new HashMap();
PropertyHolder[] props = getProps(); //RPC call here
for (PropertyHolder holder : props.list) {
map.put(holder.name,holder.value);
}
grid.setSource(map);
Consider the following class, which is intended for exchanging the information via RPC calls:
public class PropertyHolder implements IsSerializable {
public String name;
public Object value; // coudn't use Object type here
}While trying to compile this code down to javaScript, we'll get the following messages from the GWT's compiler:
org.drools.guvnor.client.ruleeditor.PropertyHolder
[java] Analyzing the fields of type 'org.drools.guvnor.client.ruleeditor.PropertyHolder' that qualify for serialization
[java] public java.lang.Object value
[java] java.lang.Object
[java] [ERROR] In order to produce smaller client-side code, 'Object' is not allowed; consider using a more specific type
[java] [ERROR] Type 'org.drools.guvnor.client.ruleeditor.PropertyHolder' was not serializable and has no concrete serializable subtypes
So that's it! I couldn't think of any solution how to cheat the compiler and leave the value's type undefined, so I have to use strings for now.
0 comments:
Post a Comment