Tuesday, May 30, 2017

Re: Code references between client/server/shared folders

I usually only call the shared code form the client (and not the other way round).
You can have separate TimeFormatter:
one for client --> 

and one for server or shared (if its used by other server side modules as well) -->
java.time.*   java.util.Date

If your TimeFormatter is in the shared module (use case: multiple server modules using it), you can tell the GWT compiler to exclude it:
<source path='shared'>

<exclude name="**/TimeFormatter.java" />


The public folder is usually used to server public assets like your  html, or external js or css files (for e.g. bootstrap or jQuery)

On Tuesday, May 30, 2017 at 11:36:01 AM UTC-4, Magnus wrote:

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