-
26 Jan 2011 2:06 AM #1
BeanModel generation with AutoBean support
BeanModel generation with AutoBean support
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.
You will also need to define this generator for use in your GWT module definition file.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); } } } } }
This definition should override the generator from the ExtGWT package.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>
Stig Runar Vangen
Waade Information System
-
28 Feb 2011 7:25 AM #2
Hi,
Thank you for sharing this. I've been looking for a way to use ExtGWT with GWT 2.1.1 RequestFactory as well, but I couldn't find any infos about this on forums, etc. I'm glad I've found your post, but I have some questions:- Did you find easy to work with ExtGWT + RequestFactory after making this patch?
- Did you encounter any other issues after doing this?
- By defining the generate-with in GWT module def file, does this mean all your *Proxy client beans will be automatically wrapped by the generator?
- Suppose you have a PersonProxy bean that has the name property. How do you specify in code that the AutoBean for this should be used for filling a TreePanel?
Thanks
-
28 Feb 2011 9:08 AM #3
Glad you liked the post.
> Did you find easy to work with ExtGWT + RequestFactory after making this patch?
We've been using this factory for over a month now, and I've never had any problems with it.
> Did you encounter any other issues after doing this?
This factory seems to work exactly like the one provided in GXT.
> By defining the generate-with in GWT module def file, does this mean all your *Proxy client beans will be automatically wrapped by the generator?
Using the generate-with replaces the GXT factory with the provided one. You will still have to tag your model classes in the same way as if you wanted them to be processable by the old factory.
> Suppose you have a PersonProxy bean that has the name property. How do you specify in code that the AutoBean for this should be used for filling a TreePanel?
You set the display property as you would do otherwise:
tree.setDisplayProperty("name");
-
28 Feb 2011 10:01 AM #4
I've tried to make one of my proxies, interface CityProxy extends ValueProxy, ModelData so that the generator will automatically generate a ModelData implementing wrapper for it. Not sure this is the way to use actually use the generator you built, but it throws this error:
[INFO] Invoking generator com.google.gwt.requestfactory.rebind.RequestFactoryGenerator
[INFO] [ERROR] The method public abstract <X extends java.lang.Object> X get(java.lang.String property) is neither a getter nor a setter
[INFO] [ERROR] Invalid Request parameterization java.util.Map
[INFO] [ERROR] Requests that return collections may be declared with java.util.List or java.util.Set only
[INFO] [ERROR] The method public abstract <X extends java.lang.Object> X remove(java.lang.String property) is neither a getter nor a setter
[INFO] [ERROR] The method public abstract <X extends java.lang.Object> X set(java.lang.String property, X value) is neither a getter nor a setter
[INFO] [ERROR] Unable to create RequestFactoryModel model due to previous errors
Also, if I try to make "City implements BeanModelTag" and remove that "CityProxy extends ModelData", the onSuccess method from my request, returns a CityProxy that doesn't extend ModelData.
Is there anything I could debug/test in order to fix this? If I did something wrong applying your solution, I'd be grateful if you could point me in the right direction.
Thanks!
-
28 Feb 2011 10:25 AM #5
Could you post the code for the Proxy and the Request? It might be easier for me to see what the problem consists of if I see the code.
-
28 Feb 2011 10:26 AM #6
Yes, just a few moments to extract it. Thank you!
-
28 Feb 2011 10:35 AM #7
-
28 Feb 2011 11:14 AM #8
All examples that I found seem to use RPC with BeanModelTag. I don't have a clear idea how to integrate RequestFactory with this. How did you make it work with RequestFactory?
Thank you!
-
28 Feb 2011 11:26 AM #9
You'll need to convert the proxy object to a BeanModel instance using the BeanModelFactory before adding it to the ModelData list. Read more on how to do this here:
http://www.sencha.com/helpcenter/ind...beanmodel.html
-
28 Feb 2011 11:29 AM #10
I'll try that, I appreciate your help with this!
Similar Threads
-
theme generation
By isit.gd in forum Community DiscussionReplies: 6Last Post: 5 Nov 2009, 12:50 AM -
Dynamic Form Generation
By jhoweaa in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 13 May 2009, 5:04 AM -
tab generation by id
By arnold07 in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 19 Dec 2008, 2:22 AM -
API doc generation
By brov0010 in forum Community DiscussionReplies: 2Last Post: 17 Dec 2007, 11:38 AM


Reply With Quote