Tuesday, May 30, 2017

Code references between client/server/shared folders


my understanding of the typical folders in a GWT project is this:
  • client
    only client-side code here
  • server
    only server-side code here
  • shared
    code that may be used on client-side and server-side
I believe that the code in the client folder gets compiled by the GWT compiler into JS only, while the code in the server folder gets compiled by javac into class files only.
Besides that, code in the shared folder gets compiled twice, once by the GWT compiler and once from javac.

My understanding always was that the code in the shared folder must be "pure" java, so that it can be compiled in both worlds, without any references into pure client-side code.

So far so good. But what happens, when code in the shared folder references some classes in the client folder?
I have just found such an example in my projects:
  • There is a class Move that represents a move in a chess game.
    It's located in the shared folder, since it's used by the server and the client.
  • The class Move uses a class TimeFormatter (to format timestamps as "yyyy-mm-dd hh:mm:ss").
    It's located in the client code and in turn uses the class com.google.gwt.i18n.client.DateTimeFormat.
What happens, when the javac compiler sees the Move class?
What does it do with com.google.gwt.i18n.client.DateTimeFormat when compiling server-side code?

Should I move TimeFormatter into the shared folder, too?
And one more step: Could you use the same time formatting code in client and server code?
(At the moment I use com.google.gwt.i18n.client.DateTimeFormat at the client and SimpleDateFormat.format at the client.)


BTW: What's the "public" folder for? I saw it in some projects but not in the docs...

You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment