View Poll Results: If you read it, did you find DirectJNgine User's Guide adequate?

Voters
54. You may not vote on this poll
  • Yes

    40 74.07%
  • No

    14 25.93%
  1. #391
    Sencha User
    Join Date
    Nov 2010
    Posts
    27
    Vote Rating
    1
    feiq is on a distinguished road

      0  

    Question Where is the solution about "how GSON works with generic collections"

    Where is the solution about "how GSON works with generic collections"


    I'm new to the thread. And I found pagullo in page 37 said, " if you take a look at how GSON works with generic collections, you'll find that there are other workarounds, but most of the time the solution I propose is easier." The thread is too long to browse, any friend know where the solution is?

    My question is:
    I have a a class like this:
    Code:
    public class DataStore<T> {
        private int total;
        private boolean success = true;
        private List<T> data;
        ...//getters and setter
    }
    And I have a direct method like this:
    Code:
    @DirectMethod
        public Object list(int start, int limit, String sort, String dir) {
        List<User> users = this.users.subList(start, Math.min(start + limit, this.users.size() - 1));
        return new DataStore<User>(users.size(), users, true);
    }
    When call this method by DirectStore, there is exception:
    java.lang.UnsupportedOperationException: Expecting parameterized type
    Are you missing the use of TypeToken idiom?
    See http://sites.google.com/site/gson/gs...ializing-Gener
    at com.google.gson.TypeInfoFactory.getActualType(TypeInfoFactory.java:97)
    ExtJS version : Ext-4.0.7
    DirectJNgine viersion: 2.0 alpha

    How to solve the problem? Or there is something I'v ignore? Thanks.

  2. #392
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Barcelona (Spain)
    Posts
    218
    Vote Rating
    19
    pagullo will become famous soon enough pagullo will become famous soon enough

      0  

    Default


    I haven't tried this, but it might work...consider creating a subclass of DataStore<P> that has no generic arguments and return an instance of that, instead of an instance of DataStore<P>. You might want to create that as a non public class to avoid polluting the code.

    This is one of those cases when one hates the fact that generics are kind of a second class feature in the language -though they are a great addition, anyway.

    Let us know whether it works, please.
    Pedro Agulló, Barcelona (Spain)
    Agile team building, consulting, training & development
    DirectJNgine: http://code.google.com/p/directjngine - Log4js-ext: http://www.softwarementors.com/projects/p/log4js-ext/

  3. #393
    Sencha User
    Join Date
    Nov 2010
    Posts
    27
    Vote Rating
    1
    feiq is on a distinguished road

      0  

    Question DirectJNgine working with Gson

    DirectJNgine working with Gson


    Hello pagullo
    I create a new Class extends the generic father class like this:

    Code:
    public class UserDataStore extends DataStore<User> {
     public UserDataStore() {
     }
     public UserDataStore(int total, List<User> data) {
      super(total, data);
     }
     public UserDataStore(int total, List<User> data, boolean success) {
      super(total, data, success);
     }
    }
    And the DirectMethod like this:
    Code:
    @DirectMethod
    public UserDataStore list(int start, int limit, String sort, String dir) {
    return new UserDataStore(users.size(), users, true); // users's type is "List<User>"
    }
    But It doesn't work.

    And Web.xml is like this:
    Code:
    <servlet>
    <servlet-name>DjnServlet</servlet-name>
    <servlet-class>
    com.softwarementors.extjs.djn.servlet.DirectJNgineServlet</servlet-class>
    <init-param>
    <param-name>debug</param-name>
    <param-value>true</param-value>
    </init-param>
    <init-param>
    <param-name>providersUrl</param-name>
    <param-value>djn/directprovider</param-value>
    </init-param>
    <init-param>
    <param-name>apis</param-name>
    <param-value>fq</param-value>
    </init-param>
    <init-param>
    <param-name>fq .apiFile</param-name>
    <param-value>directapi/Api.js</param-value>
    </init-param>
    <init-param>
    <param-name>fq.apiNamespace</param-name>
    <param-value>Fq.api</param-value>
    </init-param>
    <init-param>
    <param-name>fq.classes</param-name>
    <param-value>dms.action.UsersAction, test.ActionTest </param-value>
    </init-param>
    <!--more parameters -->
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>DjnServlet</servlet-name>
    <url-pattern>/djn/directprovider/*</url-pattern>
    </servlet-mapping>
    BTW: I know gson can press a generic class perfectly, like:
    Code:
    DataStore<User> dataStore = new DataStore<User>(users.size(), users);
    Type type = new TypeToken<DataStore<User>>() {}.getType();
    Gson gson = new Gson();
    String json = gson.toJson(dataStore, type);
    Can we use this technique to meet the need? And I hope the DirectJNgine can process generic type rightly with gson, if not, there is a lot of unnecessary class will be written, this is not a good news.

  4. #394
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Barcelona (Spain)
    Posts
    218
    Vote Rating
    19
    pagullo will become famous soon enough pagullo will become famous soon enough

      0  

    Default


    Can you provide error info regarding this last case?

    Besides, I'm really busy. So, it might be a good idea for you to narrow down the problem by creating the simplests fake generified class, returning it and checking whether the same happens. This way we can be more positive about the problem being due to the fact that the class is generic.
    Pedro Agulló, Barcelona (Spain)
    Agile team building, consulting, training & development
    DirectJNgine: http://code.google.com/p/directjngine - Log4js-ext: http://www.softwarementors.com/projects/p/log4js-ext/

  5. #395
    Sencha User
    Join Date
    Nov 2010
    Posts
    27
    Vote Rating
    1
    feiq is on a distinguished road

      0  

    Question


    Sorry for no offering the the error info for the last case. when I have a request with the DirectMethod, there occured an exception on the server:
    java.lang.UnsupportedOperationException: Expecting parameterized type
    Are you missing the use of TypeToken idiom?
    See http://sites.google.com/site/gson/gs...ializing-Gener
    at com.google.gson.TypeInfoFactory.getActualType(TypeInfoFactory.java:97)
    But you can forget the case, I have some tests for it with samplest samples.
    User class:
    Code:
    public class User {
    public User(UUID userId, String name, String email) {
    this.userId = userId;
    this.name = name;
    this.email = email;
    }
    private UUID userId;
    private String name;
    private String email;
    // getters and setters
    }
    DataStore is a class as the directmethod return type. Whether the DataStore uses genericity, there will be different result.
    (1) When DataStore is not a generic class, like this:
    Code:
    public class DataStore {
    private List<User> data;
    public DataStore(List<User> data) {
    this.setData(data);
    }
    // getters and setters
    }
    Code:
    The DirectMethod is like this:
     @DirectMethod
     public DataStore list(int start, int limit, String sort, String dir) {
      List<User> users = new Vector<User>();
      // add some users.
      return new DataStore(users);
     }
    When the browser have a request with the direct method, it can have a expected data.
    (2) When DataStore is generic class, and there is a genric property, the server will hvae an exception:
    java.lang.UnsupportedOperationException: Expecting parameterized type
    Are you missing the use of TypeToken idiom?
    See http://sites.google.com/site/gson/gs...ializing-Gener
    at com.google.gson.TypeInfoFactory.getActualType(TypeInfoFactory.java:97)
    The DataStore is like that:
    Code:
    public class DataStore<T> {
     private List<T> data; // or there is a property: private T entity.
     public DataStore(List<T> data) {
      this.setData(data);
     }
     public void setData(List<T> data) {
      this.data = data;
     }
     public List<T> getData() {
      return data;
     }
    }
    And the DirectMethod is like this:
    Code:
    @DirectMethod
    public DataStore list(int start, int limit, String sort, String dir) {
    List<User> users = new Vector<User>();
    // add some users.
    return new DataStore<User>(users);
    }
    (3) When DataStore is a generic class, but there is no generic property, It will work well too.

    Another question is that: Gson can personize a class's property, like excluding some properties. But How to do it with DirectJNgine.

  6. #396
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Barcelona (Spain)
    Posts
    218
    Vote Rating
    19
    pagullo will become famous soon enough pagullo will become famous soon enough

      0  

    Default


    Thanks for isolating and reporting the issue!

    I have added a test to check for this case, and can confirm the problem with generic types having generic fields. This is due to the fact that Gson can't cope with the generic parameter on its own because type erasure does not allow it to know the real type of generic fields. Type erasure is an unfortunate Java generics limitation.

    To deal with this the code should *explicitly* tell Gson the type of the object we want to return from the DJN method, as shown in http://sites.google.com/site/gson/gs...ializing-Gener. I can't see a clean way to do this without important changes to DJN that would go against its "hide JSON stuff from the programmer's eyes" philosophy, though I will meditate about an elegant way to cope with this.

    The solution is made much more difficult because of a much uglier issue, that of receiving generic types as parameters, instead of returning them. While I can think of an (ugly) way to handle returning such generic types, I can't think right now of a way of handling those generic types as parameters.

    I think the best way to handle this issue at the moment is to avoid using generic types with generic fields. You can keep your generic class in your model to keep it clean and crystal clear, and create simple data-only wrapper classes for interfacing with the Javascript world. Using inheritance to isolate the generic fields in derived classes should allow us to minimize code.

    Last, but not least, remember that DJN allows you to parameterize Gson so that you can write your own serializers and deserializers, etc., as explained in the user's guide. It might well be that you can find a way to put this feature to good use to handle your use case.

    Regards
    Pedro Agulló, Barcelona (Spain)
    Agile team building, consulting, training & development
    DirectJNgine: http://code.google.com/p/directjngine - Log4js-ext: http://www.softwarementors.com/projects/p/log4js-ext/

  7. #397
    Sencha User
    Join Date
    Nov 2010
    Posts
    27
    Vote Rating
    1
    feiq is on a distinguished road

      0  

    Question When call two or more Direct Method continuously

    When call two or more Direct Method continuously


    Hello pagullo,
    When I call two or more Direct Method continuously, such as:
    Code:
            UserAction.loadComplementaryRoles({userId : userId});
            UserAction.loadSubordinativeRoles({userId : userId});
    Normally, It will generate two requests, but actually, just one request was generated. This is the result from chrome15.
    Request Payload
    [{"action":"UserAction","method":"loadComplementaryRoles","data"[{"userId":"2C9083443421D164013421D170E90005"}],"type":"rpc","tid":3}, {"action":"UserAction","method":"loadSubordinativeRoles","data"[{"userId":"2C9083443421D164013421D170E90005"}],"type":"rpc","tid":4}]
    How to understand this? It has something to do with the "Action Scope"?

  8. #398
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Barcelona (Spain)
    Posts
    218
    Vote Rating
    19
    pagullo will become famous soon enough pagullo will become famous soon enough

      0  

    Default


    Unless I'm missing something, this looks as if you were inadvertently using batched requests, an Ext Direct feature DJN supports.

    For further info, check the ExtJs doc, please.

    Regards
    Pedro Agulló, Barcelona (Spain)
    Agile team building, consulting, training & development
    DirectJNgine: http://code.google.com/p/directjngine - Log4js-ext: http://www.softwarementors.com/projects/p/log4js-ext/

  9. #399
    Sencha User
    Join Date
    Sep 2010
    Posts
    27
    Vote Rating
    2
    Alinanila is on a distinguished road

      0  

    Default DirectJNgine - Spring Integration

    DirectJNgine - Spring Integration


    Hello,
    what about Spring Integration of DJN? Are there any plans to support it?
    I found out about this project, which seems to be outdated... http://code.google.com/p/directjngine-spring/

    This feature would be very helpful, as I need to register classes dynamically.

  10. #400
    Ext JS Premium Member
    Join Date
    May 2009
    Location
    Barcelona (Spain)
    Posts
    218
    Vote Rating
    19
    pagullo will become famous soon enough pagullo will become famous soon enough

      0  

    Default


    I do not have plans to support Spring directly, as it would be outstreching myself a bit too much right now.

    That said, I feel the application and session scoping support provided by DJN provides an easy way to get most of the functionality we would use Spring for.

    Regards
    Pedro Agulló, Barcelona (Spain)
    Agile team building, consulting, training & development
    DirectJNgine: http://code.google.com/p/directjngine - Log4js-ext: http://www.softwarementors.com/projects/p/log4js-ext/

Thread Participants: 86

  1. Animal (5 Posts)
  2. barton (4 Posts)
  3. Condor (1 Post)
  4. mauro_monti (6 Posts)
  5. mbarto (1 Post)
  6. aconran (1 Post)
  7. MoShAn480 (1 Post)
  8. asgillett (2 Posts)
  9. seade (4 Posts)
  10. zaqwsxqwer (3 Posts)
  11. Sesshomurai (16 Posts)
  12. ThierryC (3 Posts)
  13. maxm165 (3 Posts)
  14. techstudios (2 Posts)
  15. sayonara (2 Posts)
  16. kschlaudt (1 Post)
  17. hschaefer123 (2 Posts)
  18. omarc (2 Posts)
  19. lxbzmy (4 Posts)
  20. mct (6 Posts)
  21. mediacept (2 Posts)
  22. dionisexorcius (1 Post)
  23. alper (1 Post)
  24. steverc (2 Posts)
  25. chrizmaster (18 Posts)
  26. J@y (21 Posts)
  27. Georgioa (6 Posts)
  28. wguan (1 Post)
  29. minneyar (16 Posts)
  30. jhoweaa (1 Post)
  31. Ramez (2 Posts)
  32. malus (1 Post)
  33. dweller (8 Posts)
  34. stdunbar (1 Post)
  35. vlagorce (20 Posts)
  36. cwilliso (1 Post)
  37. Whatty (13 Posts)
  38. Ice (1 Post)
  39. clynnh (1 Post)
  40. SreevaniN (1 Post)
  41. Stsalomon90 (1 Post)
  42. GregT (9 Posts)
  43. jcalfee (6 Posts)
  44. set_ti (1 Post)
  45. maho2nd (3 Posts)
  46. dreamtaotao (3 Posts)
  47. Toxa (4 Posts)
  48. tungchau (3 Posts)
  49. wlan0 (2 Posts)
  50. jpr (2 Posts)
  51. gianmarco (5 Posts)
  52. extjslikeit (2 Posts)
  53. harmen_wessels (1 Post)
  54. Olivercomputing2 (4 Posts)
  55. vanessa_ng (2 Posts)
  56. alois.cochard (5 Posts)
  57. kyrillos52 (2 Posts)
  58. Tod (1 Post)
  59. Alinanila (1 Post)
  60. tfannon (2 Posts)
  61. Kynao (1 Post)
  62. feiq (4 Posts)
  63. dalt (1 Post)
  64. xfolch (1 Post)
  65. avijit (1 Post)
  66. marcelsnews (2 Posts)
  67. maddhippy (1 Post)
  68. sritter (1 Post)
  69. july (2 Posts)
  70. jtkeller7983 (1 Post)
  71. lfranchini (2 Posts)
  72. 7/11 (2 Posts)
  73. yAdEs (1 Post)
  74. zazz (1 Post)
  75. waqar (5 Posts)
  76. pjain11 (1 Post)
  77. alexMobimesh (2 Posts)
  78. zachHurt (4 Posts)
  79. n0n3 (5 Posts)
  80. adavis2 (1 Post)
  81. mark.peters (1 Post)
  82. lee el (4 Posts)
  83. frengo19 (3 Posts)
  84. prakashwagle (1 Post)
  85. extejnar (2 Posts)
  86. alin@sonatype.com (1 Post)