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...
com.google.gwt.i18n.client.*
java.time.* java.util.Date
<source path='shared'>
<exclude name="**/TimeFormatter.java" />
Hello,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-sideI 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...
If there are no visual classes, functionality will normally occur. Regarding your comment, javac will always be applied in all classes, regardless of what directory they are in. The classes destined to the sharing between client and server, it is sufficient to implement them without using any graphical interface.
sorry my english.
Natan.
--
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-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
The best practice is to abstract both approaches behind an interface (or abstract class), that you'd put in the "shared" package, then have concrete implementations in the "client" and "server" packages, and arrange your code to use an instance of the appropriate implementation depending on the context (using the dependency injection pattern helps here).