Announcement

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

    Sharing code between client and server

    I'm using SmartGWT EE for a type of order entry application. I need a method to calculate order totals based on the order details as they are changed by the user. The server needs the same routine to recalculate order totals based on changes that may occur server side after the order is submitted. Of course I'd like to use the same code in both instances.

    This is probably more of a GWT questions that specifically SmartGWT, but how can I define the Order object and write the method so it is usable on both client and server? The client already has all of the data available in the cache so I don't need to call the server to perform the calc. The changes the user makes are "what if" until they submit the Order and for the best response time I'd rather not make a server call if I don't need to.

    #2
    Take the non-trivial portions of the calculations and write it in such a way that it doesn't depend on libraries that GWT can't translate, and jar it up separately, making it a dependency of both your client and server-side builds. The parameters to the calculation methods should be things you can easily obtain either client or server, for example, an Array of Double or similar.

    Comment


      #3
      Instead of creating a separate jar you can also add a "source" entry in your applications module file that points to the directory that has your model classes which are GWT compatible ie. be vanilla Javabeans.

      Comment


        #4
        Ah, correct, that's an easier way to manage the dependency if your calculations don't need to be shared with future projects.

        Note that if you are using our SQL DataSource layer, Hibernate "beanless" mode, or any other system in which beans are not required, you do not need to create Order / OrderItem beans in order to share the calculation code. You can just extract the data relevant to the calculations from the server-side objects (generic data containers like HashMaps) and the client-side objects (Records, which have an accessor that produces a Map).

        Comment

        Working...
        X