Is it possible to implement RequestContext methods outside an @Entity-annotated class?
@Entity
class TheEntity {
public static TheEntity theMethod() { ... } // don't want it here
}
@Service(TheEntity.class)
interface TheEntityRequest extends RequestContext {
Request<TheEntity> theMethod(); // this one
}
Yes, you can. This is mentioned in the official GWT documentation, though it’s not very detailed.
I’ve found of great help this blog post by David Chandler.
Some pointers:
(example links are from the project discussed in the blog post)
Entity locator methods (
find,create,getId,getVersion) can be moved in a generic Locator class (example). For this to work your entities must extend a BasicEntity class that has thegetIdandgetVersionmethods. Then on the client you would specify the locator like this:Data access methods can be moved in a service. You can have a generic service (example), and then extend it for each entity to provide specific methods (example).
On the client you define your service like this:
Note the need for a service locator also. It can be as simple as this.