GWT - What to put in the shared folder?

2020-03-04 07:18发布

问题:

I'm still unsure on what to put into the shared folder. If I'm doing RPC requests, and sending Pojos from the client to the server and vice versa, do I have to put them into the shared folder (because they are used by both - client and server).

EDIT

Maybe I've used the wrong term but when I said Pojo I actually meant DTO.

回答1:

You don't have to put the RPC POJOs in a shared folder but if you keep them in the client folder, the server would be dependent on the client package because the Pojos are used both by the client and the server. It's definitely better to have client and server strictly separated, and that's what the shared folder is for.

The stuff I would put into the shared folder is:

  • RPC requests / responses - I'm using the Command pattern (gwt-dispatch)
  • Data Transfer Objects (DTOs) - lightweight objects used to transfer data
  • Input validators - logic that is shared during client-side and server-side validation
  • Shared configuration


回答2:

The shared folder must contain only code that needs to be shared both by the client and the server side. Keep in mind that this code must be executable client side, so you don't have access to some of the Java classes.

So basically any POJO or DTO class should be in the shared folder.



标签: gwt shared