We've recently converted our in development webapplication from using GWT-RPC to using RequestFactory. In this process we could not get the BeanModelGenerator to read the getters from the proxy interface. The following generator fixes this problem.
Code:
package com.wis.wisweb2.intra.core.rebind;
import java.util.List;
import com.extjs.gxt.ui.rebind.core.BeanModelGenerator;
import com.google.gwt.core.ext.typeinfo.JClassType;
import com.google.gwt.core.ext.typeinfo.JMethod;
import com.google.gwt.requestfactory.shared.BaseProxy;
/**
* BeanModel generator with support for GWT AutoBeans.
*
* @author Stig Runar Vangen
*/
public class AutoBeanBeanModelGenerator extends BeanModelGenerator {
@Override
protected final void addGetters(final JClassType cls,
final List<JMethod> methods) {
// Ignore methods of Object
if (cls.getSuperclass() != null) {
addGetters(cls.getSuperclass(), methods);
addClassGetters(cls, methods);
}
if (isAutoBean(cls)) {
addClassGetters(cls, methods);
}
}
/**
* @param cls
* class to test
* @return <i>true</i> if given class qualify for AutoBean generation
*/
private boolean isAutoBean(final JClassType cls) {
if (cls.getQualifiedSourceName().equals(BaseProxy.class.getName())) {
return true;
}
for (JClassType classType : cls.getImplementedInterfaces()) {
return isAutoBean(classType);
}
return false;
}
private void addClassGetters(final JClassType cls,
final List<JMethod> methods) {
for (JMethod m : cls.getMethods()) {
if (m.isPublic() || m.isProtected()) {
String name = m.getName();
if ((name.matches("get.*") || name.matches("is.*"))
&& m.getParameters().length == 0) {
methods.add(m);
}
}
}
}
}
You will also need to define this generator for use in your GWT module definition file.
Code:
<!-- BeanModel for AutoBean -->
<generate-with class="com.wis.wisweb2.intra.core.rebind.AutoBeanBeanModelGenerator">
<when-type-assignable class="com.extjs.gxt.ui.client.data.BeanModelLookup" />
</generate-with>
This definition should override the generator from the ExtGWT package.
Stig Runar Vangen
Waade Information System