Hybrid View

  1. #1
    Ext GWT Premium Member
    Join Date
    Jun 2010
    Location
    Kyrksæterøra, Norway
    Posts
    66
    Vote Rating
    2
    stigrv is on a distinguished road

      0  

    Default 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.

    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

  2. #2
    Sencha User
    Join Date
    Jan 2011
    Posts
    30
    Vote Rating
    0
    mxhn is on a distinguished road

      0  

    Question


    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

  3. #3
    Ext GWT Premium Member
    Join Date
    Jun 2010
    Location
    Kyrksæterøra, Norway
    Posts
    66
    Vote Rating
    2
    stigrv is on a distinguished road

      0  

    Default


    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");

  4. #4
    Sencha User
    Join Date
    Jan 2011
    Posts
    30
    Vote Rating
    0
    mxhn is on a distinguished road

      0  

    Default


    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!

  5. #5
    Ext GWT Premium Member
    Join Date
    Jun 2010
    Location
    Kyrksæterøra, Norway
    Posts
    66
    Vote Rating
    2
    stigrv is on a distinguished road

      0  

    Default


    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.

  6. #6
    Sencha User
    Join Date
    Jan 2011
    Posts
    30
    Vote Rating
    0
    mxhn is on a distinguished road

      0  

    Default


    Yes, just a few moments to extract it. Thank you!

Similar Threads

  1. theme generation
    By isit.gd in forum Community Discussion
    Replies: 6
    Last Post: 5 Nov 2009, 12:50 AM
  2. Dynamic Form Generation
    By jhoweaa in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 13 May 2009, 5:04 AM
  3. tab generation by id
    By arnold07 in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 19 Dec 2008, 2:22 AM
  4. API doc generation
    By brov0010 in forum Community Discussion
    Replies: 2
    Last Post: 17 Dec 2007, 11:38 AM

Thread Participants: 4

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi