Howto? include an outside JAR (separate project) with business objects that can be used on the Server and in the Browser Client

50 views
Skip to first unread message

Hanasaki Jiji

unread,
May 25, 2012, 2:36:55 PM5/25/12
to google-we...@googlegroups.com
I have a separate project that contains all the business domain object classes and their respective JUnit test cases.  There is no GWT in this project and a desire to keep this as purely a business object class.  How can the GWT complier be told generate the needed client side code so the same domain objects can be used in GWT based client code called by the GUI and RPC's?  I should mention that the BO project JAR built by Maven and stored in a corporate repository and the GWT project is built with the CodeHaus.org maven plugin (http://mojo.codehaus.org/gwt-maven-plugin/)  I suppose there could be two answers to this: 1. Standard GWT using ANT and 2. a Maven plugin specific way (including the BO classes in the ...client package is not an option since the resulting .class files are used in other projects).   Thus, this may end up cross posted in the Maven plugin list and GWT list.  Please pardon the cross posting should it be necessary.

Thank you.

Joseph Lust

unread,
May 26, 2012, 7:25:51 AM5/26/12
to google-we...@googlegroups.com
Jiji,

It sounds like you've almost got everything you need. You just need to include the dependency for your BO package in your GWT project POM. Myself and others use a similar design as you do, with BO in one project and GWT UI in another file.

To clarify, you can use the BO's in both the GWT client and server side code. Unless your BO's are not RPC serializable, they should just work out of the box for you. If they are not serializable to RPC, you'll need to make some DTO's to get them to the clientside. You could also use DTO's if the BO's have way more data than needed in them, to cut down on data transmission quantity/time.


Sincerely,
Joseph

hanasaki

unread,
May 26, 2012, 11:13:56 PM5/26/12
to google-we...@googlegroups.com
From your response, maybe I was thinking too deep... My thought was that
the GWT compiler does something special with BO's that are in the shared
package such that a javascript client side representation is generated
for the browser to use when serializing/deserializing the BO to/from the
server when passed over the RPC and must therefore have access to the
source (or at least the .class files to use via reflection) By
deduction, then does this mean that the GWT compiler reverse engineers a
javascript browser based javascript object based on inspection of
possible call hierarchy inspection and therefore can get the information
needed from the JAR just referenced in the pom.xml so as to be bundled
in the built _.war file?

While a big fan of the right pattern used in the right place I often
avoid the mapping and (get/set copy) of PO to BO to perhaps DTO to the
client and instead use a BO wrapper object that provides a view (MVC but
with a twist - it is a data view not a JSP view) in a specific business
object. Sometimes this is coupled with custom CODEC classes for
marshalling (serializing) / demarshaling (deserialzing) in a given usage
context. The decoder being a custom factory with a stream as a
constructor param.
> -- You received this message because you are subscribed to the
> Google Groups "Google Web Toolkit" group. To view this discussion on
> the web visit
> https://groups.google.com/d/msg/google-web-toolkit/-/kNy2t8EUP6kJ. To
> post to this group, send email to
> google-we...@googlegroups.com. To unsubscribe from this group,
> send email to google-web-tool...@googlegroups.com. For
> more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.

Joseph Lust

unread,
May 27, 2012, 10:04:20 AM5/27/12
to google-we...@googlegroups.com
 then does this mean that the GWT compiler reverse engineers a 
javascript browser based javascript object based on inspection of 
possible call hierarchy inspection and therefore can get the information 
needed from the JAR just referenced in the pom.xml so as to be bundled 
in the built _.war file? 

It has been my experience that this works in my projects, again if the RPC serialization requirements are met. I don't know exactly how it works at compile time, perhaps through reflection of accessors.

You can also override the default serialization of types in GWT with your own serializer implementation.

Joseph
Reply all
Reply to author
Forward
0 new messages