Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Using server DTOs in client gwt side.

    Hi all,
    We decided to use smartGWT + GWT RPC for some parts in our project.
    The server side is in EJB 3.0 and it uses DTO that are packaged in archive along with the session and entity beans.
    As we use smart gwt with RPC we need to duplicate every DTO, because if we use DTO class from the server project we dot an exception. I made(for test) DTO in the gwt client part and if i use it every thing is ok, but the problem is that we have duplication. Could you help, how to avoid this?
    And one other thing, could i use:
    MyClass extends DataClass implements Serializable...
    and MyClass c = new MyClass();
    c.setAtributte(someAttrName, myClassDTOFromServer.getSomeAttr);
    in order to dynamically copy the dto properties and after that i could use this MyClass instance on the client gwt code? I tried it, it didn't work :).
    Is there some kind of "DynaBean"

    Regards.

    #2
    Originally posted by mnenchev
    if we use DTO class from the server project we dot an exception
    Why do you get an exception ? Because the class isn't serializable ?
    If that should be the case one option would be to define all fields that aren't serializable as transient.
    You could also use reflection to dynamically create classes from your DTOs which can be used on the GWT client side.

    Comment


      #3
      What should i do?

      The DTOs are serializable. I add them to the build path as lib. And when i run my app in hosted mode(with cypal from eclipse) i got the following error:

      No source code is available for type claire.entity.dto.BrazierUserDTO; did you forget to inherit a required module?
      [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly

      What should i add to the entrypoint xml?
      NOTE: If i use my dto in the gwt server code(in the RPC impl) it works fine.

      Comment


        #4
        First of all: I'm not an expert on GWT RPC, as it simply seems to work for me.

        Originally posted by mnenchev
        The DTOs are serializable. I add them to the build path as lib.
        Since your DTOs need to be compiled into JavaScript for the client side, I'd guess:

        a) their source code needs to be available
        b) they have to be located below your GWT client package

        Can someone please correct me if I'm wrong ?

        Comment


          #5
          IsSerializable

          Did you try your BTO to implements IsSerializable rather than Serializable?

          See:

          http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=FAQ_RPCSerializationSupport

          E

          Comment


            #6
            Originally posted by nlotz
            First of all: I'm not an expert on GWT RPC, as it simply seems to work for me.


            Since your DTOs need to be compiled into JavaScript for the client side, I'd guess:

            a) their source code needs to be available
            b) they have to be located below your GWT client package

            Can someone please correct me if I'm wrong ?
            I think b) is correct.

            Is there a way to create a module that just looks at the package(source) that you want to look at or is the client/public/module.gwt.xml the only way to get the compiler to generate JavaScript?

            Then is there an easy way to marshall the response from SmartClient into the beans from say the Array of ListGridRecord(s)?

            Thanks,
            Eric

            Comment


              #7
              Hello, im also programming something very similar, where I have hibernate beans on the server side, i make dispatch calls using gwt-dispatch, and return dto's that are the same class as the beans themselves through a service that accesses that particular beans repository.
              Im also getting the same problem.
              My folder that holds the hibernate config info and beans is called beans and its direct parent is the "src" folder.

              Where you configure your module information (Yourproject.gwt.xml)
              you also can configure the source information in this module configurational file.
              Source Path entries can be used to specify which sub-packages contain translatable source code. Only files found on the source path are candidates to be translated into JavaScript.
              Your dto's definition must be in one of the path's defined here.
              Looks like you need to declare this path "claire.entity.dto" in your module configurational file.
              I still havent quite got this to work yet.
              Since my bean folder which has my dto's which are the beans themselves along with the hibernate config info, I dont think i can have this be a source folder since, although the bean classes themselves are simple enough to be translated over to javascript, i know that the hibernate files are server side.
              My tried solution was to create a folder that is included with the modules source path definition. In this folder, I added my bean's java definition to this folder, which goes along with my client side code. when my dispatch returns the collection of bean/dto objects, then the client side code will be able to call the definition up from the client side dto folder i created.

              Im getting an error though.

              Type mismatch: cannot convert from List<PayPeriod> to List<PayPeriod>.

              The one PayPeriod is an object that is created from my dto/bean class.
              The other PayPeriod is defined in my client side class that is referenced from the module source config.

              I use gwt Model View (Supervisor) Presenter pattern, and have a smartgwt GridList in one of my views. In my project i have a "supervisor" that converts
              the PayPeriod dto to the ListGridRecord. The collection is returned to the presenter which loads it into the ListGrid.

              Any ideas on how to get around this lil problem?






              (I know that the easy fit is to buy the smartgwt package and have the dope client to server/server to client databinding that is inherent to the non lgpl license, but I dont have that kind of money, and everything i do is an intellectual persuit that is designed to make me a better programmer.)

              Comment


                #8
                Gilead?

                http://noon.gilead.free.fr/gilead/index.php?page=overview

                Comment


                  #9
                  I would think that if one is using dependence injection framework (IoC), than one should get Guice and then instead of Gilead, use Warp Persist
                  http://www.wideplay.com/guicewebextensions2

                  but if i understand it correctly then in both cases the framework takes partially loaded POJOs and fully loads them. This might be ideal in the right situations, but if you dont need all the objects in your object persistence framework then you might want to do some other way where you can send your
                  DTO's back from the server side to the client side, have the client side
                  recognize them (meaning that it has access to the DTO's source code).

                  Is there some other way you can do this yourself?
                  Right now I have my service accessing my repository and returning a collection of my POJO objects. I dont think these are partially loaded objects, but only simple POJOs. Yet, I do get a type error because my Type of my collection of dto's being returned is different than the same class defintion, but restated in the client side.

                  Im pretty sure that this is because the client side def of that says its java but when compiled becauses a javascript class of the same or similar name, while the dto is still based on a java object.

                  Anyone see any flaws in my assessment and or have any solutions other than Gilead/and or Warp persist or paying for the non lgpl smartgwt license?

                  Thanks so much!

                  samedude

                  Comment


                    #10
                    So, after doing a bit of tinkering around, I found that you just really need
                    to add the server side folder to the (yourproject.gwt.xml) module config file.

                    ie: <source casesensitive="true" defaultexcludes="yes" path="beans"/> , etc

                    Just make sure that you only keep your pojo info in here.
                    In that folder I had my repositories, and when i ran the project, the server side still used the service/repositories, but the repositories were flagged as unknown source code because they contained classes and info specific to java that does not cross over to the gwt side.
                    Also you cant return the whole hibernate path without gilead or warp persist.
                    Make sure that your returning built collections of the bean classes, seperate from the object persistance path chain. That is, unless your DTO's are tailored differently
                    than the Bean's themselves (which is the case most of the time). If your DTO's are different than your beans than there is no way you can have a problem with
                    partially loaded objects. The only problem with that is that you cant return the objecst in a hibernate Merge operation
                    as easily because one would have to transfer the data (the data to be updated on the server side from the client side) again from the dto to the bean and then perform your merge operation...(blahhhh, thats a bitter cup of coffee!)

                    samedude
                    Last edited by thebravedave; 12 Feb 2010, 20:29.

                    Comment

                    Working...
                    X