2
votes

Description

I have a Parent GWT project that uses the gwt-maven-plugin. This project is split into 2 sub-projects: Domain and WebApp and each project contains pom.xml files. I'd like to split the domain code from GWT client code.

Parent project

  • /Parent
  • /Parent/pom.xml

Domain project

[1] I think of of it as the server-side part of the application that runs on the server

  • /Parent/Domain
  • /Parent/Domain/pom.xml
  • .../beans/PersonBean.java
  • .../dao/PersonDAO.java
  • .../services/PersonService.java
  • .../util/DateUtil.java
  • .../gwt/client/GWTPersonService.java
  • .../gwt/server/GWTPersonServiceImpl.java
  • .../gwt/shared/GWTPersonDTO.java -- a DTO(Data Transfer Object)

WebApp project

[2] I think of it as the client-side of the application that runs in the web browser.

  • Parent/WebApp
  • Parent/WebApp/pom.xml
  • .../gwt/client/PersonUI.java
  • .../gwt/util/GWTUtility.java - this is a utility class called by GWT components, it is not used on the server
  • .../webapp/WEB-INF/web.xml
  • .../webapp/Page.css
  • .../webapp/Page.html

Sequence diagram

alt text

PersonUI will call GWTPersonService's methods which calls PersonService(I need this separation because PersonService.java will be called by non-GWT clients as well).

PersonService will call PersonDAO which uses and returns PersonBean instances. Then, PersonBean gets converted to GWTPersonDTO and sent to the client by GWTPersonServiceImpl.

Questions (edited)

  1. In which project should I put the shared GWT code that normally lives under /shared folder?
  2. Does it make sense to have GWTPersonServiceImpl.java and GWTPersonService.java in the domain project? My reason is that since all servlets live on the server, and the domain is for server-side then those classes should be in the Domain project.
  3. Should I move GWTUtility.java inside Domain project?
  4. Does it make sense to use DTO's? Is there any way to make it more straight-forward: i.e. use directly the PersonBean?
  5. Is it possible to run this scenario in GWT Developer mode using maven? How easy is it to configure?
  6. If you have any modifications/additions to the above scenario, please post them - or even better if you have already done an app it would help much to know how you did to solve this separation.

Thank you!

2

2 Answers

1
votes
  1. I would put the shared code in a third project on which both Domain and WebApp can depend.
  2. Since GWTPersonServiceImpl is a servlet and runs on the server, not the client, it belongs in Domain.
  3. What function does GWTUtility perform? If it is only used on the client, it belongs in WebApp; if it is only used on the server then it belongs in Domain; if it is used on both then it probably belongs in a third project on which both WebApp and Domain depend.
  4. You can use a complex type as long as it (and its constituent types) implements either of com.google.gwt.user.client.rpc.IsSerializable or (with limitations) java.io.Serializable. See the GWT development guide for details. In any case, as designed, any serialized type in your project probably belongs in a module upon which both Domain and WebApp depend.
  5. Yes.
1
votes

I manage it as follows:

Commons
    CmnDomain [Java Project]
        src/java/com/cmnapp/CmnDomain.gwt.xml // specifying "domain" as source
        src/java/com/cmnapp/domain //  POJO's used in GWT application
        src/java/com/cmnapp/iBatis //  iBatis implementation (you can have ur DAO impl. here)
        src/java/com/myapp/service //  Common Spring service
MyApp
    MyAppService [Java Project]
        src/java/com/mynapp/MyAppDomain.gwt.xml  //  specifying "domain" as source
        src/java/com/mynapp/domain //  POJO's used in GWT application
        src/java/com/mynapp/iBatis //  iBatis implementation (you can have ur DAO impl. here)
        src/java/com/myapp/service //  Spring service
    MyAppWeb [Gwt Web Project]
        src/java/com/mynapp/MyApp.gwt.xml  //  specifying "client" and "shared" as source folders
        src/java/com/myapp/client  //  Pure GWT code can be excluded from .jar of this project
        src/java/com/myapp/shared  //  Shared between UI and Presentation tiers e.g. constants
        src/java/com/myapp/server  //  RPC servlet, Standard servlet, struts action, etc.
        src/webapp/WEB-INF/web.xml
        src/webapp/images //  images
        src/webapp/javascript //  custom java scripts
        src/webapp/css //  cascade style sheets
        src/webapp/WEB-INF/jspx //  internal access only
        src/webapp/secure  //  content accessible post user login
        src/webapp/login   //  content accessible with/without login