1. #1
    Sencha User
    Join Date
    Jun 2010
    Posts
    3
    Vote Rating
    0
    lm000000 is on a distinguished road

      0  

    Default Answered: gwt generator with sencha gxt problem

    Answered: gwt generator with sencha gxt problem


    Hello,

    I am using GWT 2.5.0 with Sencha GXT 3.0.1. I want to use com.google.gwt.core.ext.Generator to generate dynamic code for my application. I created a Web Application Project in eclipse and follow the tutorial http://francisshanahan.com/index.php...rator-example/. The example of the tutorial worked correctly. When I add in file ---.gwt.xml of my project the inherits <inherits name='com.sencha.gxt.ui.GXT'/> to use GXT in my project and compile project the generator does not work. It invoked the method PaintScreen in class ExampleScreen instead of PaintScreen defined by generator. However, in debug mode everything works fine. Only when compiling (Compile GWT) is swapping the classes

    How to solve this situation?
    thanks

  2. It is unusual that you are getting different results in dev mode vs prod mode. That said, you are doing some unusual things in your generator.

    You should almost never return null from Generator.generate. From the Javadocs:
    Code:
      /**
       * Generate a default constructible subclass of the requested type. The
       * generator throws <code>UnableToCompleteException</code> if for any reason
       * it cannot provide a substitute class
       * 
       * @return the name of a subclass to substitute for the requested class, or
       *         return <code>null</code> to cause the requested type itself to be
       *         used
       * 
       */
    (Emphasis mine)

    This means that since you return null, you are saying 'never mind, don't use my generated code after all'.

    Combine that with this (note that you are referring to ExampleScreen, not ScreenObject):
    Code:
            ScreenObject s = GWT.create(ExampleScreen.class);
    And you are asking the compiler to *either* build a generated class, *or* if you've already generated a class, go back to ExampleScreen. This is what it is doing, but apparently not what you want.

    First, change the instance of ExampleScreen to ScreenObject, which is what I think you meant. Second, never return null from the generate method - always return the string that refers to the generated class. The javadoc for context.tryCreate and other related methods says that it will return null if the file already exists - this only means that you don't need to generate it again, but just use it.

    Look at any sample generator in GWT or GXT and you'll see that this is how you are supposed to use generators.


    Additional style remark: just as GWT/Java client code usually belongs in the 'client' package, Generator code usually goes in a 'rebind' package. This code isn't run as part of the server, so really doesn't belong in the 'server' package.

  3. #2
    Sencha User
    Join Date
    Jan 2011
    Location
    Lima, Peru
    Posts
    43
    Answers
    5
    Vote Rating
    4
    poseidonjm is on a distinguished road

      0  

    Default


    I implemented successfully gwt generator with my GXT 3.0.1 project.
    I think is not problem with GXT
    If you upload a example project, I could give you some suggestions

  4. #3
    Sencha User
    Join Date
    Jun 2010
    Posts
    3
    Vote Rating
    0
    lm000000 is on a distinguished road

      0  

    Default


    Hello,
    Thanks for the reply. Here is a simple example project: http://dl.dropbox.com/u/8469536/GenTeste.zip

    If you do not add in the GenTeste.gwt.xml file the inherits module <inherits name='com.sencha.gxt.ui.GXT'/>, to use GXT, everything works correctly. When I add in this file <inherits name='com.sencha.gxt.ui.GXT'/>, in debug mode also works correctly. But when compiling the project in eclipse with GWT compile option to publish application, and deploy this over Tomcat don't works correctly. Instead of running the method PaintScreen generated by the generator, is now running the method PaintScreen of class ExampleScreen. I suppose that the compile ignores the statement <generate-with class="gen.server.WidgetGenerator"> <when-type-assignable class="gen.client.ScreenObject" /> </ generate-with> indicated in GenTeste.gwt . xml.
    Thank you for your attention

  5. #4
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,634
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      1  

    Default


    It is unusual that you are getting different results in dev mode vs prod mode. That said, you are doing some unusual things in your generator.

    You should almost never return null from Generator.generate. From the Javadocs:
    Code:
      /**
       * Generate a default constructible subclass of the requested type. The
       * generator throws <code>UnableToCompleteException</code> if for any reason
       * it cannot provide a substitute class
       * 
       * @return the name of a subclass to substitute for the requested class, or
       *         return <code>null</code> to cause the requested type itself to be
       *         used
       * 
       */
    (Emphasis mine)

    This means that since you return null, you are saying 'never mind, don't use my generated code after all'.

    Combine that with this (note that you are referring to ExampleScreen, not ScreenObject):
    Code:
            ScreenObject s = GWT.create(ExampleScreen.class);
    And you are asking the compiler to *either* build a generated class, *or* if you've already generated a class, go back to ExampleScreen. This is what it is doing, but apparently not what you want.

    First, change the instance of ExampleScreen to ScreenObject, which is what I think you meant. Second, never return null from the generate method - always return the string that refers to the generated class. The javadoc for context.tryCreate and other related methods says that it will return null if the file already exists - this only means that you don't need to generate it again, but just use it.

    Look at any sample generator in GWT or GXT and you'll see that this is how you are supposed to use generators.


    Additional style remark: just as GWT/Java client code usually belongs in the 'client' package, Generator code usually goes in a 'rebind' package. This code isn't run as part of the server, so really doesn't belong in the 'server' package.

  6. #5
    Sencha User
    Join Date
    Jun 2010
    Posts
    3
    Vote Rating
    0
    lm000000 is on a distinguished road

      0  

    Default


    Thank you very much for your help, you have been very helpful. I really can not return null from the generate method. This was really my problem.

Thread Participants: 2

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar